请问PDO为什么连接不上oracle
数据库环境Oracle 11g 64位 window server 2003
PHP环境:32位php,运行在windows XP上。
01.<?php
02.try {
03.
04. $dbh = new PDO('oci:dbname=//172.30.1.39:1521/orcl;charset=utf8', 'scott','neusoft');
05.
06. foreach($dbh->query('SELECT * from test') as $row) {
07. print_r($row);
08. print("<hr>");
09. }
10. $dbh = null;
11.} catch (PDOException $e) {
12. print "Error!: " . $e->getMessage() . "<br/>";
13. die();
14.}
15.?>
错误:
01.Error!: SQLSTATE[HY000]: OCIEnvNlsCreate: Check the character set is valid and that PHP has access to Oracle libraries and NLS data (ext\pdo_oci\oci_driver.c:558)
如果修改成
01.<?php
02.try {
03.
04. $dbh = new PDO('oci:dbname=//172.30.1.39:1521/orcl', 'scott','neusoft');
05.
06. foreach($dbh->query('SELECT * from test') as $row) {
07. print_r($row);
08. print("<hr>");
09. }
10. $dbh = null;
11.} catch (PDOException $e) {
12. print "Error!: " . $e->getMessage() . "<br/>";
13. die();
14.}
15.?>
则报错:
01.Error!: SQLSTATE[]: pdo_oci_handle_factory: <> (ext\pdo_oci\oci_driver.c:579)
[解决办法]
检查tnsnames.ora,listener.ora中,sqlnet.ora中,日志文件看看
[解决办法]
前者是字符集名称错了
关键在于后者,你的 oci 版本是否低于 oracle 版本?