连接php和oracle 11gr2 express

时间:2016-02-20 12:30:28

标签: php oracle11g oci

我一直在研究一个需要oracle数据库和php的新项目,即时通讯使用Xampp,我已经下载并安装了所有必要的配置,但我得到的错误已经证明是忙乱的,无论有多少解决方案我发现并尝试在线,我该如何解决这个问题

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

我的连接代码

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

我是oracle的新手,请帮助我如何解决这个问题。谢谢

1 个答案:

答案 0 :(得分:0)

tnsnames.ora中的数据库名称为XE,而不是localhost/XE,这意味着您的连接线可能应该是;

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

此外,在tnsnames.ora中,数据库的主机设置为JACKSOM.COM,并且应该127.0.0.1连接到localhost上的XE,即;

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