PHP and MSAccess via ODBC

A

Anonymous

Guest
First of all, please forgive me if you think this is a stupid question. I am new to PHP and have become extremely frustrated with a problem. I have installed PHP v. 4.4.0 on a Win2000 box. I am trying use an Access v. 2003 sp2 with a driver version 4.00.6200.00 through ODBC. When I do a simple "select * from tablename", it works fine. When I try to do "select id, name from tablename" it gives me an error "undefined SQLState 37000". I have tried fully qualifying the field names with the table name. I have also tried putting squared brackets around the field names and then around the table name and field name in the fully qualified version. All efforts are to no avail. When I use PHP to go against a MySQL database, the field names do not present a problem. I hope someone has the answer for me :) ...... Thanks!!
 
did you do error output to see what message did the ODBC driver return?
i think this could be a syntax problem or a wrong column name
 
The SQLState of 37000 does not have a message associated with it.
 
hmmmzz... this is very weird...
And SELECT * FROM table works fine you say...

did you try something like

"SELECT id AS id, name AS name FROM table"
 
I am gaining a very fast dislike for this development platform.
 
well..first of all: For a real application you would be suggested to use something better: like MSSQL or MYSQL and not db-wannabe Access..

Access is an Office database and not a very good one.

The error is probably because of the something going wrong in your access file.
I have just tested connecting to Access via ODBC and everything works fine.

How about you post us your code and give a sample database file that doesnt work for you and we will se what can be done..
Did you try creating another DB and connecting to it?
 
Okay, here is the code;

Code:
<?php
// This function created for making ODBC connection with databses
//	Created on 30th DEcember,2002 by Himadrish Laha himadrish@yahoo.com
$connectionstring = odbc_connect("PHPTST", "Admin", ""); 

$Query = "select Id, TstName from TestTable"; 
$queryexe = odbc_do($connectionstring, $Query); 

    while(odbc_fetch_row($queryexe)) 
    { 
     
    $cid = odbc_result($queryexe, "Id");
    $upno = odbc_result($queryexe, "TstName");
    echo "  $cid    $upno   \n";
    } 

odbc_close($connectionstring); 

exit();
?>

************************************
PHPTST points to a database with one table "TestTable" and two columns "Id" and "TstName". "Id" is an autonumber field and is the primary key. "TestTable" is a text field.

***************************************

I am aware that Access is not a good database, we are not planning on using that. At this point, I want to know what the problem is for my own sanity.
 
It has fixed the problem. One of the other programmers tried to get a host name for a connection and apparently corrupted the installed software. I don't understand how that happens, but apparently that's what it did. Thanks for all help!!
 
Back
Top