Board index   FAQ   Search  
Register  Login
Board index php forum :: Database Other Database Engines

PHP and MSAccess via ODBC

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: macek, egami, gesf

PHP and MSAccess via ODBC

Postby clemalum » Wed Oct 19, 2005 6:50 am

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!!
clemalum
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Oct 19, 2005 6:34 am

Postby Alexej Kubarev » Wed Oct 19, 2005 7:38 am

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
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

it is an 'unknown' ODBC error

Postby clemalum » Wed Oct 19, 2005 7:48 am

The SQLState of 37000 does not have a message associated with it.
clemalum
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Oct 19, 2005 6:34 am

Postby Alexej Kubarev » Wed Oct 19, 2005 7:56 am

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"
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Just tried it..... Same error;

Postby clemalum » Wed Oct 19, 2005 8:11 am

I am gaining a very fast dislike for this development platform.
clemalum
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Oct 19, 2005 6:34 am

Postby Alexej Kubarev » Wed Oct 19, 2005 8:17 am

what development platform?
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby Alexej Kubarev » Wed Oct 19, 2005 8:17 am

try using php 5 instead.. it may resolve some problems..
also check odbc reference at http://www.php.net
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

PHP

Postby clemalum » Wed Oct 19, 2005 8:18 am

This error is driving me nuts.
clemalum
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Oct 19, 2005 6:34 am

Postby Alexej Kubarev » Wed Oct 19, 2005 8:24 am

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?
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby clemalum » Wed Oct 19, 2005 9:27 am

Okay, here is the code;

Code: Select all
<?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.
clemalum
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Oct 19, 2005 6:34 am

Copy of the database I am using

Postby clemalum » Wed Oct 19, 2005 10:51 am

clemalum
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Oct 19, 2005 6:34 am

I re-installed PHP

Postby clemalum » Thu Oct 20, 2005 7:33 am

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!!
clemalum
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Oct 19, 2005 6:34 am

Postby Alexej Kubarev » Thu Oct 20, 2005 9:13 am

hehe..
That one wouldve been hard to fix :)
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län


Return to Other Database Engines

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron