Re: mdbtools with php
Jakob Egger <[email protected]> Sun, 27 Mar 2011 10:56:26 +0200
| Newsgroups | gmane.comp.db.mdb-tools.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Dale,
I found it easiest to simply call the command line tools from php (mdb-tables and mdb-export), and parse the data using the CSV functions in PHP.
However, it only makes sense if you access data a table at a time. If you only need a few records, this method is probably very slow.
As an example, here's how I read MDB databases from within php:
<?php
$file = "NWind.mdb";
foreach(tablesInFile($file) as $table) {
echo "<h1>".htmlspecialchars($table)."</h1>";
echo "<table>";
foreach(rowsInTable($file, $table) as $row) {
echo "<tr>";
foreach($row as $columnName=>$columnValue) {
echo "<td>".htmlspecialchars($columnValue)."</td>";
}
echo "/<tr>";
}
echo "</table>";
}
function tablesInFile($file) {
exec("/usr/bin/mdb-tables -1 " . escapeshellarg($file), $tables );
return $tables;
}
function rowsInTable($file, $table) {
$csv = popen("/usr/bin/mdb-export -q \\\" -X \\\\ " . escapeshellarg($file) . " " . escapeshellarg($table), "r");
$header = fgetcsv($csv);
$rows = array();
while($row=fgetcsv($csv)) {
$rows[] = array_combine($header, $row);
}
return $rows;
}
?>
Best regards,
Jakob
On 26.03.2011, at 21:15, Dale Scott wrote:
> Hi, how is mdbtools being used with php? I first tried pecl-mdbtools. Now I'm trying ODBC (via unixODBC). Are there other and/or better methods?
>
> Also, I'm having trouble with either unixODBC or mdbtools segfaulting when I try to open a database, so I'm rebuilding everything from scratch on a new install of FreeBSD-7.4-RELEASE with latest ports to make sure I don't have a problem with wrong versions of libraries or something. If anyone has any suggestions, I'm all ears (it will be tomorrow until I can run the tests again).
>
> Dale
>
>
> ------------------------------------------------------------------------------
> Enable your software for Intel(R) Active Management Technology to meet the
> growing manageability and security demands of your customers. Businesses
> are taking advantage of Intel(R) vPro (TM) technology - will your software
> be a part of the solution? Download the Intel(R) Manageability Checker
> today! http://p.sf.net/sfu/intel-dev2devmar_______________________________________________
> mdbtools-dev mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mdbtools-dev
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
mdbtools-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mdbtools-dev