题
如果查询没有返回行,那么 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(资源$语句[,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";
}
?>
不隶属于 StackOverflow