Page 1 of 1

simple connection issue

Posted: Mon Nov 14, 2005 6:01 pm
by JasonTC
I'm working with an Access database. When I started at this job, there was already a working database in place. I've recently created a new one, but it doesn't work for some reason. The connection code is:

db_connection.php

Code: Select all

<?php

$db_connection = NULL;
$db_name = 'mail';
$db_user = NULL;
$db_password = 'xxxxxxx';

if (!($dbConnection = @ odbc_connect($db_name, $db_user, $db_password))) {
	echo "Could not connect to the database.";
}
	
ob_start('ob_gzhandler');
@session_start();

?>
Then, in another script, I have:

login.php

Code: Select all

<php

include_once('db_connection.php');

$sql = "SELECT * FROM logins;";
odbc_exec($db_connection, $sql);
?>
I get the error:

Code: Select all

Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in c:\wwwroot\taxsale\mail\login.php on line 70
The "logins" table definitely exists. I've added this database in Data Sources in the Control Panel. What did I miss?

Thanks,
Jason

Posted: Mon Nov 14, 2005 6:04 pm
by Charles256
maybe put the variables in double quotes? just a guess that's easy enough to try out...

Posted: Mon Nov 14, 2005 6:07 pm
by JasonTC
Same results. Before I added my db to the Data Sources, I was getting the "Could not connect to the database" error, but afterward it went away. So it looks like the problem is not the connection itself, but possibly something to do with the query.

Posted: Mon Nov 14, 2005 6:15 pm
by timvw
You have $dbConnection and $db_connection

Posted: Mon Nov 14, 2005 6:19 pm
by JasonTC
Fixed it. Thanks a lot.

Posted: Mon Nov 14, 2005 6:21 pm
by Charles256
man..gotta learn to read...heh