0

我对 PHP 有一个非常奇怪的问题。

我运行这个非常简单的代码:

include("db_credentials.php");
//
$conn = mysql_connect($host, $user, $pass);
$sel = mysql_select_db($db, $conn);
  //
  $result = mysql_query("SELECT * FROM tokens");
  $res = mysql_num_rows($result);
  //
echo (50000-$res);

但最终的减法结果永远不会正确。我试过echo gettype($res)并且$res是一个整数(它还能是什么?),但我不知道是什么原因造成的。它是一个PHP错误吗?我的代码有问题吗?

4

1 回答 1

1

I'm pretty sure I've run into this before but can't remember exactly where or how.

This isn't an answer per say, but rather a suggestion.

Try this code instead

include("db_credentials.php");
$conn = mysql_connect($host, $user, $pass);
$sel = mysql_select_db($db, $conn);

$result = mysql_query("SELECT COUNT(*) as count FROM tokens");
$row = mysql_fetch_assoc($result);
$res = $row['count'];

echo (50000-$res);
于 2012-04-15T19:16:29.077 回答