当前位置: 首页 > 工具软件 > Oracle+PHP > 使用案例 >

php连接oracle数据库

孟海
2023-12-01
function test()
{
    $tns = "  
        (DESCRIPTION =
            (ADDRESS_LIST =
                  (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 2521))
            )
            (CONNECT_DATA =
              (SERVICE_NAME = orcl)
            )
          )
       ";
    $username = "username";
    $password = "password";
    $conn = new \PDO('oci:dbname=' . $tns . ';charset=ZHS16GBK', $username, $password);
    try {
        $sql = "select 1 from dual";
        $rs = $conn->prepare($sql);
        $rs->execute();
        $id = $rs->fetch();
        var_dump($id);
    } catch (Exception $e) {
        var_dump($e->getMessage());
    }
}

 类似资料: