工作代码 -
$dbh = new PDO('oci:dbname=localhost/XE', 'hr', 'hr');
$s = $dbh->prepare("select * from Employees");
$s->execute();
while (($r = $s->fetch(PDO::FETCH_ASSOC)) != false) {
echo htmlentities($r['FIRST_NAME']) . " " . $r['LAST_NAME'] . "<br>";
}
无效代码 (错误调用未定义函数oci_connect(),oci_new_connect())
/*Using oci_connect */
$conn=oci_connect("hr","hr","localhost/XE");
If (!$conn)
echo 'Failed to connect to Oracle';
else
echo 'Succesfully connected with Oracle DB';
oci_close($conn);
/*Using oci_new_connect*/
$c = oci_new_connect('hr', 'hr', 'localhost/XE');
$s = oci_parse($c, 'select city from locations');
oci_execute($s);
while (($res = oci_fetch_array($s, OCI_ASSOC)) != false) {
echo htmlentities($res['CITY']) . "<br>";
}
phpinfo为phpinfo details 我已经在c中放置了11g的instantclient并设置了PATH变量
逐个尝试每个即时客户端扩展程序 -
答案 0 :(得分:0)
OCI_CONNECT需要服务器上的TNSNAMES.ORA文件。主机名(作为IP)仅在域控制器注册名称时有效。
<?php
$oracleHost="IP or Hostname";
$oracleLogin="username";
$oraclePassword="passworrd";
$oraclePort="1521";
$oracleSid="sidname";
$tns="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$oracleHost)(PORT=$oraclePort))(CONNECT_DATA=(SID=$oracleSid)))";$oracleConnect = oci_connect($oracleLogin,$oraclePassword, $tns);
?>