simple connection issue

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
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

simple connection issue

Post 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
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

maybe put the variables in double quotes? just a guess that's easy enough to try out...
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You have $dbConnection and $db_connection
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Post by JasonTC »

Fixed it. Thanks a lot.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

man..gotta learn to read...heh
Post Reply