Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP5, Access, Apache problems

Status
Not open for further replies.
Aug 23, 2004
174
US
I am trying to connect to an ms access database on apache and keep getting this error: Failed to fetch error message.

Here is my code:
Code:
	$conn = odbc_connect("roster","","");
	if (!conn)
	{exit("Connection Failed: " .$conn);}
        else
	{
		$sql = "SELECT id, state, county FROM roster";
		$result = odbc_exec($conn, $sql) or die (odbc_errormsg());
		if (!result)
		{exit("Error in SQL");}
                else
		{odbc_result_all($result);}
	}
        odbc_close($conn);

Can anyone help me out?
 
always have error checking when you develop. add an errormsqg to your connection to see why tis failing to connect.

Code:
$conn = odbc_connect("roster","","") [red]or die (odbc_errormsg());[/red]



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for the reply. I added that line and im still getting the same error. I think its coming from this line
Code:
$result = odbc_exec($conn, $sql) or die (odbc_errormsg());
 
Can you post the full error?

It might be that your query returns no rows to be fetched.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
This is all I get for the error: Failed to fetch error message.

My database has over 2000 rows in it, so it should be returning something.
 
given that the error is a Fetch error, i suspect it is coming from the odbc_result_all() function.

there are known bugs with some odbc datatypes that report this error. google a bit for the error message and see whether anything rings true. also consider debugging by using a simple odbc_fetch_row() or similar cursor based approach. it might be that there's some bad data or corrupt row causing problems.
 
Ok, so it turns out to be an issue with connecting to the database. Does anyone have an article or site about connecting to an access database with php5?
 
Here is the entire error I am getting now:

Warning: odbc_connect() [function.odbc-connect]: SQL error: Failed to fetch error message, SQL state HY000 in SQLConnect in C:\web\apache\htdocs\subcarrier\newsites.php on line 31

Code:
$conn = odbc_connect("roster","",""); ***line 31
if (!$conn)
{
  exit("Connection Failed: " .$conn);
}else
{
     $sql = "SELECT id, state, county FROM roster";
     $result = odbc_exec($conn, $sql);
     if (!$result)
     {	exit("Error in SQL");
     }else
	{odbc_result_all($result);}
}
	odbc_close($odbc);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top