Php, Oracle And Odbc: How To Check If Result Set Is Empty?
Dear nerds and forumianers, I have a delicious problem with PHP on a Oracle database with ODBC driver. First the code: $ora_conn = odbc_connect($ora_dsn, $ora_user, $ora_pass, SQL_
Solution 1:
odbc_num_rows seems to be reliable for INSERT, UPDATE, and DELETE queries only.
The manual says:
Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with many drivers.
one way around this behaviour is to do a COUNT(*) in SQL instead. See here for an example.
Solution 2:
if(odbc_num_rows( $ora_data ) == 0){
//do something incase no result came back
}
if(!$ora_data){
//do something incase result came back
}
Solution 3:
I solved it, thank you for your answers...
My solution is: Code first
$sql = "SELECT GUID FROM SMSITEACCESS WHERE PROJECTID = 901981 AND SID = " . $guid;
$ora_data = odbc_exec($ora_conn,$sql);
$arr = @odbc_fetch_array($ora_data);
if($arr['GUID'] == ""){
$dbh_insert = new PDO($dsn,$dbuser,$dbpass);
$dbh_insert->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql_insert = "INSERT INTO SMSITEACCESS (SID, CREATED, CREATEUSER, PROJECTID) VALUES ('".$guid."', SYSDATE, '".$userid."', '901981')";
$res_insert = $dbh_insert -> prepare($sql_insert);
$res_insert -> execute();
$sql_insert=null;
$res_insert=null;
$dbh_insert=null;
}
odbc_free_result($ora_data);
I added an include file firstly. This script checks one by one if every table to be worked with consists at last of one data set. If any of it doesn´t, it is created empty.
With this workaround I do not anymore have to check if data coming back or not...
It could have been much easier but ODBC-driver seams to be buggy in this con-sens.
Thnx for fast replies and have a good day.
Ingmar
Post a Comment for "Php, Oracle And Odbc: How To Check If Result Set Is Empty?"