简体   繁体   English

为什么我的PHP没有显示任何东西? (代码包括在内)

[英]why my php does not show anything ? (code is included)

This code should give a table of the table cats. 这段代码应该给出表猫的表格。 However, it shows a blank page. 但是,它显示一个空白页面。 It seems the query part does not work. 似乎查询部分不起作用。 It cannot go to ' var_dump($results) '. 它不能去' var_dump($results) '。 However, I can create a table using codes having been commented. 但是,我可以使用已注释的代码创建表。 So what is the problem ? 那么问题是什么?

<?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);
?>

The mysql_query() line is missing a ';' mysql_query()行缺少';' at the end: 在末尾:

$query = "DESCRIBE cats";
$results = mysql_query($query);

var_dump($results);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM