Only Single Column Return: PHP/Linux/PDO
Don Pitchford <[email protected]> Wed, 20 Jan 2016 17:23:45 -0500
| Newsgroups | gmane.comp.db.mdb-tools.devel |
|---|---|
| Message-ID | <CAGFxWMN=WJgHSavp019aBTNa5ojqx=Og-YMTxM7koX8JqPyUxQ@mail.gmail.com> |
--===============8920513491770573627==
Content-Type: multipart/alternative; boundary=089e013a0c1e76bdda0529cb700e
--089e013a0c1e76bdda0529cb700e
Content-Type: text/plain; charset=UTF-8
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.
--089e013a0c1e76bdda0529cb700e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div><div>Hi,<br><br></div>I am experimenting with re=
ading Access Database (.mdb) using Linux (Ubuntu 12.04 64bit) computer with=
the MDBTools installed.<br><br></div>I have installed the MDBTools based o=
n this website (<a href=3D"https://gist.github.com/amirkdv/9672857">https:/=
/gist.github.com/amirkdv/9672857</a>)=C2=A0 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.=C2=A0=C2=A0=C2=A0 When I do SELECT * from areacode, only=
the first column is populated with the data, the rest of the columns are b=
lank / null, but the column names come across.=C2=A0=C2=A0 <br><br></div><d=
iv>However, any column with alphanumeric values, does not load.=C2=A0=C2=A0=
Such as SELECT Region from areacodes; returns nothing.=C2=A0=C2=A0=C2=A0 <=
br><br></div><div>BTW - I copied the areacode database from above link.=C2=
=A0 I reconfigured the table to remove the spaces from the table name and c=
olumn names.=C2=A0 (Wasn't sure how to handle that in SQL.).=C2=A0=C2=
=A0 I added some additional columns for testing purpose.=C2=A0=C2=A0 If you=
want that data, I can send it as well.=C2=A0 Its 500K.<br></div><div><br><=
/div><div>Any case, here is my code.=C2=A0=C2=A0 Can anyone shed any light =
on what I might be doing wrong.<br><br><br></div>Php Code:<br><br><div styl=
e=3D"margin-left:40px"><?php<br>error_reporting(-1);<br>ini_set('dis=
play_errors','On');<br>ini_set('display_errors',1);<br>=
ini_set('display_startup_errors',1);<br><br>$query =3D 'SELECT =
* FROM areacodes';<br>$mdb_file =3D 'areacodes.mdb';<br>$uname =
=3D explode(" ",php_uname());<br>$os =3D $uname[0];<br>switch ($o=
s){<br>=C2=A0 case 'Windows':<br>=C2=A0=C2=A0=C2=A0 $driver =3D =
9;{Microsoft Access Driver (*.mdb)}';<br>=C2=A0=C2=A0=C2=A0 break;<br>=
=C2=A0 case 'Linux':<br>=C2=A0=C2=A0=C2=A0 echo "Linux\r\n&quo=
t;;<br>=C2=A0=C2=A0=C2=A0 $driver =3D 'MDBTools';<br>=C2=A0=C2=A0=
=C2=A0 break;<br>=C2=A0 default:<br>=C2=A0=C2=A0=C2=A0 exit("Don't=
know about this OS");<br>}<br>$dataSourceName =3D "odbc:Driver=
=3D$driver;DBQ=3D$mdb_file;";<br>$db =3D new PDO($dataSourceName);<br>=
$sth =3D $db->prepare($query);<br>$sth -> execute();<br><br>foreach($=
sth as $row) {<br><br>=C2=A0=C2=A0=C2=A0 print_r(array_value($row));<br><br=
>}<br><br>?><br><br><br></div>Output:=C2=A0=C2=A0 Only the first field s=
hows there is data, rest of the fields come in blank.=C2=A0 (I only copy a =
single record.. all the records are the same.=C2=A0=C2=A0 Not sure why the =
data is duplicated.=C2=A0 I should only have 6 columns (areacode, Region,jo=
hn,today,oktouse,NextNbr,howmuch).=C2=A0=C2=A0 <br><br><br><div style=3D"ma=
rgin-left:40px">..<br>Array<br>(<br>=C2=A0=C2=A0=C2=A0 [0] =3D> 9.400000=
0000000000e+02<br>=C2=A0=C2=A0=C2=A0 [1] =3D> 9.4000000000000000e+02<br>=
=C2=A0=C2=A0=C2=A0 [2] =3D> <br>=C2=A0=C2=A0=C2=A0 [3] =3D> <br>=C2=
=A0=C2=A0=C2=A0 [4] =3D> <br>=C2=A0=C2=A0=C2=A0 [5] =3D> <br>=C2=A0=
=C2=A0=C2=A0 [6] =3D> <br>=C2=A0=C2=A0=C2=A0 [7] =3D> <br>=C2=A0=C2=
=A0=C2=A0 [8] =3D> <br>=C2=A0=C2=A0=C2=A0 [9] =3D> <br>=C2=A0=C2=A0=
=C2=A0 [10] =3D> <br>=C2=A0=C2=A0=C2=A0 [11] =3D> <br>=C2=A0=C2=A0=C2=
=A0 [12] =3D> <br>=C2=A0=C2=A0=C2=A0 [13] =3D> <br><br>..<br></div><d=
iv><div><div><div><div><div><div><div><br><br><div style=3D"margin-left:40p=
x"><b>cat /etc/odbcinst.ini </b><br>[MDBTools]<br>Description=C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 =3D MDBTools Driver<br>Driver=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =3D libmdbodbc.so.1<br>Setup=C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 =3D libmdbodbc.so.1<br>FileUsage=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =3D 1<br>UsageCount=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =3D 1<br></=
div><br><div style=3D"margin-left:40px">cat /etc/odbc.ini=C2=A0 (Blank)<br>=
<br><br clear=3D"all"></div><div><div class=3D"gmail_signature"><br>Don Pit=
chford<br><a href=3D"http://www.vectare.com/" target=3D"_blank">VECTARE</a>=
<br>+1.703.962.7154 (office)<br>+1.703.272.8510 (fax)<br>+1.703.627.1171 (c=
ell)<br><br><font style=3D"background-color:rgb(255,255,255);color:rgb(153,=
153,153)" size=3D"1">This email and any files transmitted=20
with it are confidential and intended solely for the use of the ind=
ividual=20
or entity to whom they are addressed. If you have received this ema=
il=20
in error please notify the system manager. This message contains co=
nfidential=20
information and is intended only for the individual named. If you a=
re=20
not the named addressee you should not disseminate, distribute or c=
opy=20
this e-mail. Please notify the sender immediately by e-mail if you =
have=20
received this e-mail by mistake and delete this e-mail from your sy=
stem.=20
If you are not the intended recipient you are notified that disclos=
ing,=20
copying, distributing or taking any action in reliance on the conte=
nts=20
of this information is strictly prohibited. </font><br style=3D"bac=
kground-color:rgb(255,255,255);color:rgb(153,153,153)"><br><br><br></div></=
div>
</div></div></div></div></div></div></div></div></div>
--089e013a0c1e76bdda0529cb700e--
--===============8920513491770573627==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
--===============8920513491770573627==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
mdbtools-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mdbtools-dev
--===============8920513491770573627==--