<?php
function escapeIdentifier($name)
{
$name = str_replace('`', '``', $name);
$name = trim($name);
$name = '`' . $name . '`';
return $name;
}
function printTable($tblname, $con)
{
$result = mysql_query("SELECT * FROM " . escapeIdentifier($tblname) . "
ORDER BY `id` ASC", $con);
echo '<table border="1">';
$first = true;
while ($row = mysql_fetch_assoc($result)) {
if ($first) {
// Spaltennamen ausgeben
echo '<tr><th>'
. implode('</th><th>', array_keys($row))
. '</th></tr>';
$first = false;
}
echo '<tr><td>' . implode('</td><td>', $row) . '</td></tr>';
}
echo '</table>';
}
error_reporting(-1);
$host = 'localhost';
$username = '';
$password = '';
$dbname = 'tests';
$tblname = 'foo';
$con = mysql_connect($host, $username, $password);
mysql_select_db($dbname, $con);
printTable($tblname, $con);