FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Query *.mdb file with ODBC functions
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Query *.mdb file with ODBC functions [message #170281] Tue, 26 October 2010 15:20 Go to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
Sometimes I'm handled data in a Microsoft Access database and I need to
manipulate it. I only have an old copy of Access 2000, I'm not
proficient with it, I don't know the query syntax and I hate its GUI to
the bone. In the past, I used to migrate data to another DBMS, do stuff
there and then port back to the original file, but it's an error-prone
and time-consuming method.

I've found that writing a simple PHP script with the ODBC functions (I
have a Windows box) can ease the task a lot. However, I have two
important questions so far:

1.- What exact SQL dialect does the JET engine expect? I'd appreciate a
link to MSDN or something with an explanation of basic syntax and
available functions.

2. How am I supposed to escape input data? PHP ODBC functions provide
parametrized queries but I can't make them work:

$data = array(
100 => 'Foo St.',
101 => 'Bar Ave.',
);
$sql = 'UPDATE street
SET name=?
WHERE code=?';
$stmt = odbc_prepare($conexion, $sql);
if( $stmt===FALSE ){
die(odbc_errormsg());
}
foreach($data as $code => $name){
if( !odbc_execute($stmt, array($name, $code)) ){
die(odbc_errormsg()); // SQL state 07001 Wrong number of parameters
}
}

Some user comments in the PHP manual suggest that parametrized queries
are not supported by the Access driver :-?



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Query *.mdb file with ODBC functions [message #170283 is a reply to message #170281] Tue, 26 October 2010 16:41 Go to previous messageGo to next message
Robert Hairgrove is currently offline  Robert Hairgrove
Messages: 19
Registered: September 2010
Karma: 0
Junior Member
Álvaro G. Vicario wrote:
> Sometimes I'm handled data in a Microsoft Access database and I need to
> manipulate it. I only have an old copy of Access 2000, I'm not
> proficient with it, I don't know the query syntax and I hate its GUI to
> the bone. In the past, I used to migrate data to another DBMS, do stuff
> there and then port back to the original file, but it's an error-prone
> and time-consuming method.
>
> I've found that writing a simple PHP script with the ODBC functions (I
> have a Windows box) can ease the task a lot. However, I have two
> important questions so far:
>
> 1.- What exact SQL dialect does the JET engine expect? I'd appreciate a
> link to MSDN or something with an explanation of basic syntax and
> available functions.

The best reference for ODBC is the "ODBC Programmer's Reference" which
somes with every edition of Visual Studio and can be easily located on
the Microsoft MSDN web site if you search for the term "ODBC".

MS-Access SQL is slightly different than the SQL which ODBC supports,
but if you are connecting via ODBC, then you need to stick to the ODBC
documented syntax. I believe that the MS-Access ODBC driver supports at
least the ODBC API level 3.51 (Access 2000 was able to support it, IIRC
-- there might be a higher level, but I think ODBC support was pretty
much dropped by Microsoft in favor of OLEDB many years ago, more or less
when Windows XP came out or even before that).

There are ODBC functions (SQLGetInfo, I think it is called) which can be
used to fetch a large variety of meta-data in order to find the level of
support you have at runtime. For applications using ODBC, it is a good
habit to use this ODBC API for discovering the support level at runtime,
regardless of whether you have an MS-Access "database" or some other
kind of RDBMS at the back end.

> 2. How am I supposed to escape input data? PHP ODBC functions provide
> parametrized queries but I can't make them work:

Escaping literal text strings with ODBC must be done using single quote
characters (MS-Access SQL running inside Access accepts either single or
double quotes). Date strings, however, must be formatted according to
the ODBC docs if you want to pass a literal date value to an Access
database using ODBC. Most other data can be passed normally. There are
some "gotchas" regarding Boolean data (i.e. Access interprets "true" as
a long integer value of -1).

> Some user comments in the PHP manual suggest that parametrized queries
> are not supported by the Access driver :-?

This is highly likely. Note that any ODBC application connecting to an
MS-Access database is not going to have any support from the server,
simply because there is none (except for the file server where the MDB
file is located). And every time you query an Access database located on
a remote computer, you will download the entire MDB file.

Also, you cannot run any queries stored in the Access MDB file which
contain calls to VBA functions (even built-in functions such as iif())
because they need the MS-Access executable in order to run. You will
find that many of the built-in VBA functions can be replaced by ODBC
function calls, though.
Re: Query *.mdb file with ODBC functions [message #170303 is a reply to message #170283] Thu, 28 October 2010 07:28 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 26/10/2010 18:41, Robert Hairgrove escribió/wrote:
> Álvaro G. Vicario wrote:
>> Sometimes I'm handled data in a Microsoft Access database and I need
>> to manipulate it. I only have an old copy of Access 2000, I'm not
>> proficient with it, I don't know the query syntax and I hate its GUI
>> to the bone. In the past, I used to migrate data to another DBMS, do
>> stuff there and then port back to the original file, but it's an
>> error-prone and time-consuming method.
>>
>> I've found that writing a simple PHP script with the ODBC functions (I
>> have a Windows box) can ease the task a lot. However, I have two
>> important questions so far:
>>
>> 1.- What exact SQL dialect does the JET engine expect? I'd appreciate
>> a link to MSDN or something with an explanation of basic syntax and
>> available functions.
>
> The best reference for ODBC is the "ODBC Programmer's Reference" which
> somes with every edition of Visual Studio and can be easily located on
> the Microsoft MSDN web site if you search for the term "ODBC".
>
> MS-Access SQL is slightly different than the SQL which ODBC supports,
> but if you are connecting via ODBC, then you need to stick to the ODBC
> documented syntax. I believe that the MS-Access ODBC driver supports at
> least the ODBC API level 3.51 (Access 2000 was able to support it, IIRC
> -- there might be a higher level, but I think ODBC support was pretty
> much dropped by Microsoft in favor of OLEDB many years ago, more or less
> when Windows XP came out or even before that).
>
> There are ODBC functions (SQLGetInfo, I think it is called) which can be
> used to fetch a large variety of meta-data in order to find the level of
> support you have at runtime. For applications using ODBC, it is a good
> habit to use this ODBC API for discovering the support level at runtime,
> regardless of whether you have an MS-Access "database" or some other
> kind of RDBMS at the back end.
>
>> 2. How am I supposed to escape input data? PHP ODBC functions provide
>> parametrized queries but I can't make them work:
>
> Escaping literal text strings with ODBC must be done using single quote
> characters (MS-Access SQL running inside Access accepts either single or
> double quotes). Date strings, however, must be formatted according to
> the ODBC docs if you want to pass a literal date value to an Access
> database using ODBC. Most other data can be passed normally. There are
> some "gotchas" regarding Boolean data (i.e. Access interprets "true" as
> a long integer value of -1).
>
>> Some user comments in the PHP manual suggest that parametrized queries
>> are not supported by the Access driver :-?
>
> This is highly likely. Note that any ODBC application connecting to an
> MS-Access database is not going to have any support from the server,
> simply because there is none (except for the file server where the MDB
> file is located). And every time you query an Access database located on
> a remote computer, you will download the entire MDB file.
>
> Also, you cannot run any queries stored in the Access MDB file which
> contain calls to VBA functions (even built-in functions such as iif())
> because they need the MS-Access executable in order to run. You will
> find that many of the built-in VBA functions can be replaced by ODBC
> function calls, though.

Thank you for all the pointers.

I presume that PHP+ODBC+Access is not the most powerful tool-set in the
world but there aren't many alternatives to handle an *.mdb file from
PHP, are there?



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Query *.mdb file with ODBC functions [message #170309 is a reply to message #170281] Thu, 28 October 2010 14:34 Go to previous messageGo to next message
Adrienne Boswell is currently offline  Adrienne Boswell
Messages: 25
Registered: October 2010
Karma: 0
Junior Member
Gazing into my crystal ball I observed "lvaro G. Vicario"
<alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid> writing in news:ia6rk6$6su$1
@news.eternal-september.org:

> Some user comments in the PHP manual suggest that parametrized queries
> are not supported by the Access driver :-?
>
>

If you look for postings from Bob Barrows in
microsoft.public.inetserver.asp.general for parameterized queries, you
will find that he recommends them a lot for Access.

For example:
http://groups.google.com/group/microsoft.public.inetserver.asp.db/msg/c96
6c9c8eb98f331

and:
http://groups.google.com/group/microsoft.public.inetserver.asp.db/msg/72e
36562fee7804e?pli=1

This might be helpful:
http://sqlserver2000.databases.aspfaq.com/what-are-the-main-differences-
between-access-and-sql-server.html

Yes, I realize this is a PHP group, but the DBMS is the same.
--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Re: Query *.mdb file with ODBC functions [message #170310 is a reply to message #170309] Thu, 28 October 2010 15:17 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 28/10/2010 16:34, Adrienne Boswell escribió/wrote:
> Gazing into my crystal ball I observed "Álvaro G. Vicario"
> <alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid> writing in news:ia6rk6$6su$1
> @news.eternal-september.org:
>
>> Some user comments in the PHP manual suggest that parametrized queries
>> are not supported by the Access driver :-?
>>
>>
>
> If you look for postings from Bob Barrows in
> microsoft.public.inetserver.asp.general for parameterized queries, you
> will find that he recommends them a lot for Access.
>
> For example:
> http://groups.google.com/group/microsoft.public.inetserver.asp.db/msg/c96
> 6c9c8eb98f331
>
> and:
> http://groups.google.com/group/microsoft.public.inetserver.asp.db/msg/72e
> 36562fee7804e?pli=1

His advise appears to be to use "the OleDB provider" instead of the
"obsolete ODBC driver". If in ASP it's just a matter of changing the
connection string then they must be closely related. I need to test
whether it's the same in PHP.


> This might be helpful:
> http://sqlserver2000.databases.aspfaq.com/what-are-the-main-differences-
> between-access-and-sql-server.html

Oh, very nice link, thank you very much.


> Yes, I realize this is a PHP group, but the DBMS is the same.

Problems that involve several tecnologies are doomed to be offtopic
everywhere :)



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Timezone is changing to default
Next Topic: Syntax for adding text prefix to a post variable?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 17:07:58 GMT 2024

Total time taken to generate the page: 0.03094 seconds