If col1 is a text column, use ... WHERE [col1] = 'some text' (note the use of quotation marks) for an exact match.
... WHERE [col1] LIKE 'xxx' equivalent to ... WHERE [col1] = 'xxx' .
When using LIKE the wildcard character % matches zero or more characters, and _ matches one character, so
... WHERE [col1] LIKE 'To%'
must match Toronto, Tokyo, Toledo, etc ....
Edit
The manual page for the mdb-sql MDB Tools command claims to support LIKE , so I put together a test .mdb file with a table named [Clients] containing
ID LastName FirstName Email -- ---------- -------------- ------------------ 1 Thompson Gord gord@example.com 2 Loblaw Bob bob@example.com 3 Kingsley Hank hank@example.com 4 Thompson Hunter S. hunter@example.com
I did sudo apt-get install mdbtools on my test server (Ubuntu 04/12/02), downloaded the .mdb file and did the following
gord@pingu :~$ mdb-sql -p ~/ubuTest2003.mdb 1 => SELECT ID, LastName FROM Clients 2 => go ID LastName 1 Thompson 2 Loblaw 3 Kingsley 4 Thompson 4 Rows retrieved 1 => SELECT ID, LastName FROM Clients WHERE LastName LIKE 'Thomp%' 2 => go ID LastName 1 Thompson 4 Thompson 2 Rows retrieved
If you are having difficulty with WHERE clauses, I would suggest running a similar test (with a small sample dataset) on your system using mdb-sql to see if the WHERE clauses work in this context. If they do not work, your MDB tools are broken. If they really work, we will need to continue research.
Edit
I spent some time trying to recreate this problem in PHP on a Ubuntu 12.04 test server. I could not do this just because I was unable to get the odbc_ functions in PHP to work with mdbtools in general . I can establish the “correct” connection (without errors), and I could “execute” the request (again, without errors), but I could not get any request to actually return results, not even SELECT * FROM Clients .
In search of help with my problem, I came across a Stack Overflow article, which further prevented me from continuing to consider this issue.
Instead, since this is apparently an active Access database hosted on a Windows computer, I personally would prefer to use ODBTP . This is a free TCP / IP (GPL) protocol that allows you to transfer requests to a Windows computer, which then sends the request through its ODBC driver and sends the results back to you.
This requires the service to be installed and running on a Windows machine, and the PHP client component must be compiled into Linux boxes, but if these requirements are not too complicated, then this is a pretty reliable solution for this type of problem. (I have used it several times in the past.)
Although it is true that ODBTP has not been updated for several years, it still works: I tested it only now when my LAMP server ran the following PHP script to request a .mdb file located on my old Vista laptop:
<?php echo '<html><body><pre>'; echo "ODBTP test:\n"; $con = odbtp_connect('192.168.1.254', 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\__tmp\\ubuTest.mdb;UID=admin;PWD=;'); if (!$con) die('_connect error: ' . odbtp_get_error($con)); $rst = odbtp_query("SELECT * FROM Clients WHERE LastName LIKE 'Thomp%'"); if (!$rst) die('_query error: ' . odbtp_get_error($con)); while ($row = odbtp_fetch_assoc($rst)) { echo $row['ID'] . ': ' . $row['LastName'] . "\n"; } echo '</pre></body></html>';
Results displayed in my browser window
ODBTP test: 1: Thompson 4: Thompson