简体   繁体   中英

connecting php and oracle 11gr2 express

i have been working on a new project which requires oracle database and php,im using Xampp and i have downloaded and installed all the necessary configurations but i'm getting the errors below which have proven to be hectic no matter how many solutions i found and tried online,how do i resolve this

Warning: oci_connect(): ORA-12514: TNS:listener does not currently know of service requested in connect descriptor in C:\xampp\htdocs\Dos\index.php on line 3

Warning: oci_parse() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Dos\index.php on line 6

Warning: oci_error() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Dos\index.php on line 8

Fatal error: in C:\xampp\htdocs\Dos\index.php on line 9

MY CONNECTION CODE

<?php

$conn = oci_connect('blue','password','localhost/XE');

// Prepare the statement
$stid = oci_parse($conn, 'SELECT * FROM  persons');
if (!$stid) {
    $e = oci_error($conn);
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

// Perform the logic of the query
$r = oci_execute($stid);
if (!$r) {
    $e = oci_error($stid);
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

// Fetch the results of the query
print "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    print "<tr>\n";
    foreach ($row as $item) {
        print "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    print "</tr>\n";
}
print "</table>\n";


?>

TSNAMES.ORA

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = JACKSOM.COM)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

ORACLR_CONNECTION_DATA = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) 
    ) 
    (CONNECT_DATA = 
      (SID = CLRExtProc) 
      (PRESENTATION = RO) 
    ) 
  ) 

LISTENER.ORA

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = JACKSON.COM)(PORT = 1522))
    )
  )

DEFAULT_SERVICE_LISTENER = (XE)

SQLNET.ORA

SQLNET.AUTHENTICATION_SERVICES = (NTS)

i'm new to oracle kindly help on how i can go about this..thanks

Your database name in tnsnames.ora is XE , not localhost/XE , which means your connect line should probably be;

$conn = oci_connect('blue','password','XE');

Also, in tnsnames.ora , the host for the database is set to JACKSOM.COM and should probably be 127.0.0.1 to connect to XE on localhost, that is;

XE =
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1522))
   (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME = XE)
   )
 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM