这段代码应该给出表猫的表格。但是,它显示一个空白页面。似乎查询部分不起作用。它无法转到“var_dump($results)
”。但是,我可以使用已注释的代码创建表。那么问题是什么?
<?php
require_once "login.php";
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if(!$db_server)
die("Unable to connect: ".mysql_error());
mysql_select_db($db_database, $db_server) or die("Unable to select a db: ".mysql_error());
/*
$query = "CREATE TABLE cats
(
id SMALLINT NOT NULL AUTO_INCREMENT,
family VARCHAR(32) NOT NULL,
name VARCHAR(32) NOT NULL,
age TINYINT NOT NULL,
PRIMARY KEY (id)
)";
mysql_query($query) or die("Create cats DB failed: ".mysql_error());
*/
$query = "DESCRIBE cats";
$results = mysql_query($query)
var_dump($results);
if(!$results)
die("Error-line22: ".mysql_error());
else
echo $results."<br />";
$rows = mysql_num_rows($results);
echo "<table>";
echo "
<tr> <th>Column</th> <th>Type</th> <th>NULL</th> <th>Key</th> </tr>";
for ($j = 0; $j < $rows; ++$j)
{
$row = mysql_fetch_row($results);
echo "<tr>";
for ($k = 0; $k < 4; ++$k)
echo "<td>$row[$k]</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($db_server);
?>
答案 0 :(得分:2)
mysql_query()行缺少';'最后:
$query = "DESCRIBE cats";
$results = mysql_query($query);
var_dump($results);