<?php
$tns = "(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=cqrac))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.98.100)(PORT=1521)))";
function select_data($conn,$sql)
{
$stmt = oci_parse($conn,$sql);
oci_execute($stmt, OCI_DEFAULT);
echo $conn."----selecting\n\n";
while (oci_fetch($stmt)) {
echo $conn . " [" . oci_result($stmt, "TABLE_NAME") . "]\n\n";
}
echo $conn . "----done\n\n";
}
try {
$dbconn = oci_connect("username", "password",$tns,'utf8');
$sql= "select table_name from user_tables";
var_dump(oci_error());
select_data($dbconn,$sql);
}
catch (Exception $e) {
echo $e->getMessage();
}
?> 更详细的参考见:
http://php.net/manual/zh/function.oci-connect.php 如果要在页面输出,取出函数返回结果集
function select_data($conn,$sql)
{
$stmt = oci_parse($conn,$sql);
oci_execute($stmt, OCI_DEFAULT);
echo $conn."----selecting\n\n";
return $stmt;
}
后台打印出来即可:
$result=select_data($dbconn,$sql);
oci_fetch_all($result,$array);
echo "<pre>";
var_dump($array);
echo "<br>";
echo "</pre>";