Don Pitchford
2016-01-20 22:23:45 UTC
Hi,
I am experimenting with reading Access Database (.mdb) using Linux (Ubuntu
12.04 64bit) computer with the MDBTools installed.
I have installed the MDBTools based on this website (
https://gist.github.com/amirkdv/9672857) I modified the sample PHP code
and I can read the MDB data, but only one column at a time and only if the
column is numeric. When I do SELECT * from areacode, only the first
column is populated with the data, the rest of the columns are blank /
null, but the column names come across.
However, any column with alphanumeric values, does not load. Such as
SELECT Region from areacodes; returns nothing.
BTW - I copied the areacode database from above link. I reconfigured the
table to remove the spaces from the table name and column names. (Wasn't
sure how to handle that in SQL.). I added some additional columns for
testing purpose. If you want that data, I can send it as well. Its 500K.
Any case, here is my code. Can anyone shed any light on what I might be
doing wrong.
Php Code:
<?php
error_reporting(-1);
ini_set('display_errors','On');
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
$query = 'SELECT * FROM areacodes';
$mdb_file = 'areacodes.mdb';
$uname = explode(" ",php_uname());
$os = $uname[0];
switch ($os){
case 'Windows':
$driver = '{Microsoft Access Driver (*.mdb)}';
break;
case 'Linux':
echo "Linux\r\n";
$driver = 'MDBTools';
break;
default:
exit("Don't know about this OS");
}
$dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;";
$db = new PDO($dataSourceName);
$sth = $db->prepare($query);
$sth -> execute();
foreach($sth as $row) {
print_r(array_value($row));
}
?>
Output: Only the first field shows there is data, rest of the fields come
in blank. (I only copy a single record.. all the records are the same.
Not sure why the data is duplicated. I should only have 6 columns
(areacode, Region,john,today,oktouse,NextNbr,howmuch).
..
Array
(
[0] => 9.4000000000000000e+02
[1] => 9.4000000000000000e+02
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
..
*cat /etc/odbcinst.ini *
[MDBTools]
Description = MDBTools Driver
Driver = libmdbodbc.so.1
Setup = libmdbodbc.so.1
FileUsage = 1
UsageCount = 1
cat /etc/odbc.ini (Blank)
Don Pitchford
VECTARE <http://www.vectare.com/>
+1.703.962.7154 (office)
+1.703.272.8510 (fax)
+1.703.627.1171 (cell)
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the system manager.
This message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and
delete this e-mail from your system. If you are not the intended recipient
you are notified that disclosing, copying, distributing or taking any
action in reliance on the contents of this information is strictly
prohibited.
I am experimenting with reading Access Database (.mdb) using Linux (Ubuntu
12.04 64bit) computer with the MDBTools installed.
I have installed the MDBTools based on this website (
https://gist.github.com/amirkdv/9672857) I modified the sample PHP code
and I can read the MDB data, but only one column at a time and only if the
column is numeric. When I do SELECT * from areacode, only the first
column is populated with the data, the rest of the columns are blank /
null, but the column names come across.
However, any column with alphanumeric values, does not load. Such as
SELECT Region from areacodes; returns nothing.
BTW - I copied the areacode database from above link. I reconfigured the
table to remove the spaces from the table name and column names. (Wasn't
sure how to handle that in SQL.). I added some additional columns for
testing purpose. If you want that data, I can send it as well. Its 500K.
Any case, here is my code. Can anyone shed any light on what I might be
doing wrong.
Php Code:
<?php
error_reporting(-1);
ini_set('display_errors','On');
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
$query = 'SELECT * FROM areacodes';
$mdb_file = 'areacodes.mdb';
$uname = explode(" ",php_uname());
$os = $uname[0];
switch ($os){
case 'Windows':
$driver = '{Microsoft Access Driver (*.mdb)}';
break;
case 'Linux':
echo "Linux\r\n";
$driver = 'MDBTools';
break;
default:
exit("Don't know about this OS");
}
$dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;";
$db = new PDO($dataSourceName);
$sth = $db->prepare($query);
$sth -> execute();
foreach($sth as $row) {
print_r(array_value($row));
}
?>
Output: Only the first field shows there is data, rest of the fields come
in blank. (I only copy a single record.. all the records are the same.
Not sure why the data is duplicated. I should only have 6 columns
(areacode, Region,john,today,oktouse,NextNbr,howmuch).
..
Array
(
[0] => 9.4000000000000000e+02
[1] => 9.4000000000000000e+02
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
..
*cat /etc/odbcinst.ini *
[MDBTools]
Description = MDBTools Driver
Driver = libmdbodbc.so.1
Setup = libmdbodbc.so.1
FileUsage = 1
UsageCount = 1
cat /etc/odbc.ini (Blank)
Don Pitchford
VECTARE <http://www.vectare.com/>
+1.703.962.7154 (office)
+1.703.272.8510 (fax)
+1.703.627.1171 (cell)
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the system manager.
This message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and
delete this e-mail from your system. If you are not the intended recipient
you are notified that disclosing, copying, distributing or taking any
action in reliance on the contents of this information is strictly
prohibited.