database connection problems

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
whyong
Forum Newbie
Posts: 1
Joined: Fri Jun 14, 2002 4:22 am

database connection problems

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
verabug
Forum Newbie
Posts: 16
Joined: Tue Jun 11, 2002 7:53 pm
Location: San Francisco, CA
Contact:

Post by verabug »

When you do an Access/PHP connection like this, do the database and the scripts have to live on the same machine?
Post Reply