ITPub博客

首页 > 数据库 > Oracle > php连接oracle数据库代码(转) Lin 杰

php连接oracle数据库代码(转) Lin 杰

Oracle 作者:pixiaohui 时间:2013-01-20 20:03:33 0 删除 编辑

$ora_host = "172.19.*.259"; $ora_port="1521"; $ora_sid = "orasid"; $ora_username = "orauser"; $ora_password = "orapwd"; $charset = "UTF8"; ### zhs16gbk ### $ora_connstr = "(description=(address=(protocol=tcp) (host=".$ora_host.")(port=".$ora_port.")) (connect_data=(service_name=".ora_sid.")))"; $conn = oci_connect($ora_username, $ora_password,$ora_connstr); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR,$charset); } $stid = oci_parse($conn, 'SELECT * FROM employees'); oci_execute($stid); echo " "; while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { echo " "; foreach ($row as $item) { echo " "; } echo " "; } echo "
" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "
";



php连接oracle数据库代码

php教程连接oracle数据库教程代码
  $conn    OCILogon("scott","tiger","你的oracle数据库名字");   
  $stmt    OCIParse($conn,"select   empno,   ename   from   emp");   
     
  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数据库代码二
  
  if ($conn=Ora_Logon("user@TNSNAME","password")) 
 
  echo "SUCCESS ! Connected to databasen"; 
 }
 else 
 {
  echo "Failed :-( Could not connect to databasen";
 
 Ora_Logoff($conn);

//连接数据库实例三

 $connection = Ora_Logon ("webmaster@111cn.net", "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函数解析过的查询。

<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26187442/viewspace-1117395/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2011-08-19