PHP连接oracle数据库
function connect_oracle()
{
//以下是变量(数据库连接的配置)
$host = "127.0.0.1";
$port = "1521";
$sid = "root";
$sname = "root";
$db_user = "root";
$db_pwd = "root";
if ((!$conn = $this->connect_oracle2($host, $port, $sid, $sname, $db_user, $db_pwd)))
{
//是否得到数据库链接
return "connot connect the Oracle database"; exit;
}
//return $conn;
$sql = "SELECT * FROM table";
$PMD = oci_parse($conn,$sql);
oci_execute($PMD,OCI_DEFAULT); //执行
while($r=oci_fetch_array($PMD,OCI_ASSOC)) //取回结果
{
$res[] =$r;
}
var_dump($res);
die();
}
//连接数据库方法
function connect_oracle2($host, $port, $sid, $sname, $db_user, $db_pwd)
{
$db = " (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = $host)(PORT = $port)) (CONNECT_DATA = (SID=$sid) (SERVER = DEDICATED) (SERVICE_NAME = $sname) ) )";
$dbconn = oci_connect($db_user, $db_pwd, $db,'UTF8');
return $dbconn;
}
connect_oracle();