2016-07-15 42 views
0

工作代碼 -連接到Oracle:使用PDO的作品,但使用oci_connect不

$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 我已經把instantclient在C 11g和設置PATH變量也


想盡instantclient擴展一個由單

  1. 延長= php_oci8.dll,
  2. 延長= php_oci8_11g.dll,
  3. extension = php_oci8_12c.dll

我使用Oracle 11g

嘗試須─thisthis also

回答

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); 
     ?>