连接 php 和 oracle 11gr2 express
connecting php and oracle 11gr2 express
我一直在开发一个需要 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) : " ") . "</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.2.0\server)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product.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 的新手,请帮助我解决这个问题..谢谢
您在 tnsnames.ora
中的数据库名称是 XE
,而不是 localhost/XE
,这意味着您的连接线可能是;
$conn = oci_connect('blue','password','XE');
此外,在 tnsnames.ora
中,数据库的主机设置为 JACKSOM.COM
并且可能应该是 127.0.0.1
以连接到本地主机上的 XE
,即;
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
我一直在开发一个需要 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) : " ") . "</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.2.0\server)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product.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 的新手,请帮助我解决这个问题..谢谢
您在 tnsnames.ora
中的数据库名称是 XE
,而不是 localhost/XE
,这意味着您的连接线可能是;
$conn = oci_connect('blue','password','XE');
此外,在 tnsnames.ora
中,数据库的主机设置为 JACKSOM.COM
并且可能应该是 127.0.0.1
以连接到本地主机上的 XE
,即;
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)