[英]mysql_num_rows always zero, despite of reality
I have mySQL datanase installed, with phpMyAdmin to administer it. 我安装了mySQL datanase,并使用phpMyAdmin对其进行管理。 I have a test database with one "users" table and one row I have put in. 我有一个带有一个“用户”表和一行的测试数据库。
In phpMyAdmin, when I do "SELECT * from users" I am receiving my one row correctly. 在phpMyAdmin中,当我执行“ SELECT * from users”时,我正确地收到了我的一行。
Now I've built a small PHP hello world page.It connects to the very same database, with a fully privileged user credential I've opened. 现在我建立了一个小的PHP hello world页面,它使用我打开的具有完全特权的用户凭证连接到相同的数据库。 It submits the same query, but for some strange reason, the mysql_num_rows is always zero 它提交相同的查询,但是由于某些奇怪的原因, mysql_num_rows始终为零
Here's the code I use. 这是我使用的代码。 Please note I am seeing the following debug messages on my web page when I load it: 请注意,加载网页时,我在网页上看到以下调试消息:
success so far
success so far 2
No Rows
Here's the code I'm using: 这是我正在使用的代码:
<?php
if (!$link = mysql_connect('localhost', 'testuser', 'testpw')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('MYDB', $link)) {
echo 'Could not select database';
exit;
}
echo 'success so far<br>';
$sql = 'SELECT * FROM users';
$result = mysql_query($sql, $link) or die(mysql_error());
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
echo 'success so far 2<br>';
$countt = mysql_num_rows($result);
if($count>0)
{
echo "we have rows";
}
else
{
echo "No Rows";
}
while ($row = mysql_fetch_assoc($result)) {
echo $row['foo'];
}
mysql_free_result($result);
?>
I'd appreciate any pointers as to what I'm doing wrong. 对于任何我做错的事情,我将不胜感激。 As you can tell - I'm a php newbie. 如您所知-我是php新手。
$countt
has two t's 有两个
if($count>0)
so $count
is undefined 所以$count
是不确定的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.