0

if 的条件是什么,我想在 if 中执行一些命令,如果查询没有返回行。

<?php
  include_once('config.php');
  $db = oci_new_connect(ORAUSER,ORAPASS,"localhost/XE");
  $sql="select * from table_1 where id=3";
  $result=oci_parse($db,$sql);
  oci_result($result);

  if()
  {

  }
  else
  {

  }
?>
4

2 回答 2

1

你可以使用oci_fetch

// parse/bind your statement

if (oci_fetch($your_statement)) {
    ... // do something when there is rows
}    
else {
    ... // do something when there is no rows
}
于 2010-02-02T15:33:19.193 回答
0

使用 oci_parse() 分配绑定值后,您需要使用oci_execute()运行查询。这是函数定义:

bool oci_execute ( 资源 $statement [, int $mode = OCI_COMMIT_ON_SUCCESS ] )

成功时返回 TRUE,失败时返回 FALSE。

把它们放在一起:

<?php

$stmt = oci_parse($conn, $sql);
$res = oci_execute($stmt);
if( !$res ){
    $error = oci_error($stmt);
    echo "Error: " . $error['message'] . "\n";
}else{
    echo "OK\n";
}

?>
于 2010-02-02T15:41:41.030 回答