oci_parse的返回值

发布于 2024-08-20 12:01:16 字数 303 浏览 4 评论 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
  {

  }
?>

what will be the condition of if , where i want to execute some command inside if ,if there is no row returned by the query.

<?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
  {

  }
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

壹場煙雨 2024-08-27 12:01:16

你可以使用 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
}

you could use 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
}
淡忘如思 2024-08-27 12:01:16

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

bool oci_execute(资源
$语句[,int $模式=
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";
}

?>

After assigning the bind values with oci_parse(), you need to run the query with oci_execute(). This is the function definition:

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

Returns TRUE on success or FALSE on failure.

Putting it all together:

<?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";
}

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文