Help: Can't get results returned from query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
stoferj
Forum Newbie
Posts: 1
Joined: Thu Jan 16, 2003 2:20 pm
Location: Ohio

Help: Can't get results returned from query

Post by stoferj »

Hi, I'm trying to connect to an Oracle DB from an NT/IIS/PHP server. I'm getting connected but the query isn't returning anything. I get the message that it connected successfully but then it just spins its wheels. Any help appreciated. Here is my test script.

<?PHP

if ($conn_id = odbc_connect("dev", "test", "test")) {
echo("Connection successful!");
$result = odbc_exec($conn_id, "SELECT SYSDATE FROM DUAL");
odbc_fetch_row($result);
$field1 = odbc_result($result, 1);
echo($field1);

odbc_close($conn_id);
} else {
echo("Cannot connect to data source");
}
?>
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Perhaps the problem is here.

Code: Select all

$result = odbc_exec($conn_id, "SELECT SYSDATE FROM DUAL");
The reason being that you have no idea if the query ran with success or not. Why not check $result and see what is returned. You could also use odbc_num_rows() to find out how many rows were found.

Cheers,
BDKR
Post Reply