Skip to content

Instantly share code, notes, and snippets.

@remoharsono
Last active August 13, 2018 02:55
Show Gist options
  • Save remoharsono/8ef943bedab437e3fb2b to your computer and use it in GitHub Desktop.
Save remoharsono/8ef943bedab437e3fb2b to your computer and use it in GitHub Desktop.
Simple PHP script to list table names and field names when accessing MS Access database via DSN-less ODBC
<?php
// get table names
$username = 'Admin';
$password = 'blablabla';
$db = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\\xampp\htdocs\pblablabla.mdb;", $username, $password);
$result = odbc_tables($db);
echo '<div id="top">..</div><table border="1" cellpadding="5"><tr>';
$tblRow = 1;
while (odbc_fetch_row($result)){
if(odbc_result($result,"TABLE_TYPE")=="TABLE"){
$tableName = odbc_result($result,"TABLE_NAME");
echo '<tr><td>' . $tblRow . '</td><td><a href="#' . $tableName . '">' . $tableName . '</a></td></tr>';
$tblRow++;
}
}
echo '</table><hr>';
$result = odbc_tables($db);
while (odbc_fetch_row($result)){
if(odbc_result($result,"TABLE_TYPE")=="TABLE"){
$tableName = odbc_result($result,"TABLE_NAME");
echo '<div id="' . $tableName . '"> *** ' . $tableName . ' *** <a href="#top">top</a></div>';
$cols = odbc_exec($db, "SELECT * FROM $tableName WHERE 1=2");
$ncols = odbc_num_fields($cols);
for ($n=1; $n<=$ncols; $n++) {
$field_name = odbc_field_name($cols, $n);
echo $field_name . "<br>";
}
echo '<hr>';
}
}
@BlaxWalker
Copy link

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment