0

Working code-

$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>";
}

Not working code (Error-Call to undefined function 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 are as phpinfo details I have placed instantclient for 11g in c and set PATH variable also


Tried every instantclient extensions one by one-

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

I am using Oracle 11g

Tried also- this and this also

Community
  • 1
  • 1

1 Answers1

0

OCI_CONNECT required TNSNAMES.ORA file on server. Hostname (as IP) only works if domain controller register name.

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