php连接oracle数据库代码
php连接oracle数据库代码
php连接oracle数据库代码连接oracle代码
$conn = OCILogon("scott","tiger","你的oracle数据库名字");
$stmt = OCIParse($conn,"select empno, ename from emp");
/* 使用 OCIDefineByName 要在执行 OCIExecute 前 */
OCIDefineByName($stmt,"EMPNO",&$empno);
OCIDefineByName($stmt,"ENAME",&$ename);
OCIExecute($stmt);
while (OCIFetch($stmt)) {
echo "empno:".$empno."n";
echo "ename:".$ename."n";
}
OCIFreeStatement($stmt);
OCILogoff($conn);
/*
注明:
php默认状态下是不能与oracle数据库连接的,我们得 在php.ini的Windows Extensions段修改成
extension_dir = "所要加载的dll的文件路径" (如c:phpextensions)
extension=php_oci8.dll
extension=php_oracle.dll
第二步:
iis中设置isapi
*/
//php连接oracle数据库代码二
if ($conn=Ora_Logon(""))
{
echo "SUCCESS ! Connected to databasen";
}
else
{
echo "Failed :-( Could not connect to databasen";
}
Ora_Logoff($conn);
//连接数据库实例三
$connection = Ora_Logon ("", "123");
if ($connection == false){
echo Ora_ErrorCode($connection).": ".Ora_Error($connection)."";
exit;
}
$cursor = Ora_Open ($connection);
if ($cursor == false){
echo Ora_ErrorCode($connection).": ".Ora_Error($connection)."";
exit;
}
Ora_Commit ($connection);
Ora_Close ($cursor);
Ora_Logoff ($connection);
/*
说明函数功能:
integer ora_logon(string user , string password)根据指定用户连接oracle数据库服务器
integer ora_open(integer connection)给出的连接上执行查询。PHP生成一个指示器,解析查询
integer ora_do(integer connection, string query)为查询并准备好执行
integer ora_parse(integer cursor, string query)ora_parse函数解析过的查询。