编写一个脚本来打印数据库中存在的所有表的内容...... 但不幸的是我在某个地方出错了。谁能告诉我哪里出错了?
$sql = "SHOW TABLES FROM $dbName";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
for ($i=1; $i<=5; $i++)
{
while ($row = mysql_fetch_row($result))
{
echo "Table: {$row[0]}\n";
$sql_1 = "SELECT * FROM {$row[0]}";
$result_1 = mysql_query($sql_1);
$row_1 = mysql_fetch_row($result);
echo "$row_1";
}
}
mysql_free_result($result);
?>
感谢..
答案 0 :(得分:0)
首先,你不需要
for ($i=1; $i<=5; $i++)
另外,$ row_1是一个数组,所以要打印它使用类似
的东西print_r($row_1);
表中可能没有唯一的行,所以使用像
这样的构造while ($row = mysql_fetch_row($result))
{
echo "Table: {$row[0]}\n";
$sql_1 = "SELECT * FROM {$row[0]}";
$result_1 = mysql_query($sql_1);
while ($row_1 = mysql_fetch_row($result_1/*There was also an error*/))
print_r($row_1); /*Print_r or other function to print an array*/
}