質問

クエリによって返された行がない場合、 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
  {

  }
?>
役に立ちましたか?

解決

あなたが使用することができます 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
}

他のヒント

oci_parse() を使用してバインド値を割り当てた後、次のコマンドを使用してクエリを実行する必要があります。 oci_execute(). 。これは関数定義です。

bool oci_execute(resource $ 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";
}

?>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top