要使用php连接oracle,基本条件是
1.需要你安装了php、
2.安装了oracle、
3.配置了tnsname.ora。
本地命令行使用sqlplus能够连接到oracle。
根据你机器的版本选对64bit或者32bit的php程序,我们使用php的oci8扩展连接oracle
安装好php后,打开oci8扩展,
写一段连接oracle的ora.php代码
$conn = oci_connect(\'hr\', \'welcome\', \'MYDB\');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e[\'message\'], ENT_QUOTES), E_USER_ERROR);
}
// Prepare the statement
$stid = oci_parse($conn, \'SELECT * FROM departments\');
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\";
oci_free_statement($stid);
oci_close($conn);
?>
本文地址:https://www.stayed.cn/item/8157
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我