列出列表中mysql表的所有行

时间:2014-11-10 13:26:54

标签: php mysql performance

我想列出另一个表中特定mysql表的所有行。但是我得到了这个错误。我搜索所有谷歌的东西,但我找不到任何东西。请帮帮我!

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in 

C:\xampp\htdocs\toate.php on line 38
There are currently rows in the table

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\toate.php on line 42

这是我的PHP代码:

$user = "boss";
$pass = "123";
$db = "test";
$link =  mysql_connect("localhost", $user, $pass );

if ( ! $link ){
    die( "Couldn't connect to MySQL" );
}

mysql_select_db( $db, $link ) or die ( "Couldn't open $db: ".mysql_error() );
$result = mysql_query( "SELECT * FROM Employee" );

$num_rows = mysql_num_rows( $result );
print "There are currently $num_rows rows in the table<P>";
print "<table border=1>\n";

while ( $a_row = mysql_fetch_row( $result ) ){
    print "<tr>\n";
    foreach ( $a_row as $field )
        print "\t<td>$field</td>\n";
    print "</tr>\n";
}

print "</table>\n";
mysql_close( $link );

1 个答案:

答案 0 :(得分:0)

由于权限错误,您的查询似乎失败了。如果发生这种情况,mysql_query()将返回FALSE。查看您的用户的数据库权限。另外,我建议使用mysqli,因为不推荐使用mysql扩展。

编辑:mysql_result在错误时也返回false,因此请确保仔细检查查询语法。