Page 1 of 1

database connection problems

Posted: Fri Jun 14, 2002 4:22 am
by whyong
when i try to connect to the access db thru odbc, it gives the error msg:

"Warning: odbc_result_all(): supplied argument is not a valid ODBC result resource in C:\Program Files\Apache Group\Apache2\htdocs\test1.php on line 9

Warning: odbc_free_result(): supplied argument is not a valid ODBC result resource in C:\Program Files\Apache Group\Apache2\htdocs\test1.php on line 10"

for you information, i'm using php 4.2.1.
and i didn't change anythings in php.ini file.

below is the code of the php page:-

<?php
$connection = odbc_connect("webdb","","") or die ("Couldn't connect to the datasource.");

// create SQL statement
$sql = "select custcode, custname, birthdate from table1";

$sql_statement = odbc_prepare($connection,$sql) or die ("Couldn't prepare statement.");
$sql_result = odbc_execute($sql_statement) or die ("Couldn't execute query.");
odbc_result_all($sql_result, "border=1");
odbc_free_result($sql_result);
odbc_close($connection);
?>

PLEASE HELP!!

Thanks!! :D

Posted: Fri Jun 14, 2002 4:53 am
by twigletmac
Try,

Code: Select all

<?php 
$connection = odbc_connect('webdb','','') or die ('Couldn't connect to the datasource.<br />'.odbc_errormsg()); 

// create SQL statement 
$sql = "SELECT custcode, custname, birthdate FROM table1"; 

$sql_statement = odbc_prepare($connection, $sql) or die ('Couldn't prepare statement.<br />'.odbc_errormsg()); 
$sql_result = odbc_execute($sql_statement) or die ('Couldn't execute query.<br />'.odbc_errormsg()); 
odbc_result_all($sql_result, 'border=1') or die(odbc_errormsg()); 
odbc_free_result($sql_result) or die(odbc_errormsg()); 
odbc_close($connection); 
?>

Hopefully odbc_errormsg() will give you a more meaningful error message.

Mac

Posted: Fri Jun 14, 2002 9:48 am
by verabug
When you do an Access/PHP connection like this, do the database and the scripts have to live on the same machine?