samer
samer

Reputation: 193

can not connect to oracle database using php

I am using XAMPP version 5.6.15 to run my PHP file on windows 10.

But I am getting this error message:

Fatal error: Call to undefined function oci_connect() in F:\xampp\htdocs\Sbank\index.php on line 4

According to PHP docs everything should work fine.

<?php

$conn = oci_connect('admin', 'admin', 'localhost/JDT');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, 'SELECT sysdate FROM dual');
oci_execute($stid);

echo $stid;


?>

Upvotes: 1

Views: 1949

Answers (3)

samer
samer

Reputation: 193

problem solved by following details steps within below youtube.com tutorial

youtube link

Upvotes: 0

Aman Maurya
Aman Maurya

Reputation: 1325

If instant client has been installed but the full oracle client not yet ,you can use pdo to connect to oracle database like following coding:

<?php
$tns = " 
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = yourip)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
       ";
$db_username = "youname";
$db_password = "yourpassword";
try{
    $conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
}catch(PDOException $e){
    echo ($e->getMessage());
}
?>

Source : http://php.net/manual/en/ref.pdo-oci.php

Upvotes: 1

Alexanderp
Alexanderp

Reputation: 341

Please ensure you have OCI8 extension enabled. check output of phpinfo() or extension_loaded ('extension name') or in CLI php -m

Upvotes: 1

Related Questions