php 连接oracle

$conn = oci_connect('111','111',"(DESCRIPTION=(ADDRESS=(PROTOCOL =TCP)(HOST=10.101.0.36)(PORT = 1521))(CONNECT_DATA =(SID=orcl)))");
  
  if (!$conn) {
   $e = oci_error();
   var_dump($e['message']);
   //trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  }

  $sql1 = "select * from nls_database_parameters"; // 查询字符集
  $sql2 = "select userenv('language') from dual"; // 查询字符集
  $sql3 = "select * from file ";

  $sql4 = "INSERT INTO file VALUES ('123010101','1')";
 
  echo "start\n";

  $stmt = oci_parse($conn, "$sql4");
  oci_execute($stmt, OCI_DEFAULT);

  $committed = oci_commit($conn);
  if (!$committed) {
         $error = oci_error($conn);
         echo 'Commit failed. Oracle reports: ' . $error['message'];
     };


  while ($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS)) {
   foreach ($row as $item) {
    echo ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "\n";
   };
  };
  echo "end\n";

  var_dump( oci_close($conn) );

posted @ 2015-07-09 11:20  山河水  阅读(353)  评论(0编辑  收藏  举报