在没有应用任何条件的情况下,对表中的行总数进行计数的最佳MySQL命令是什么?我正在通过php执行此操作,所以也许有一个php函数可以为我执行此操作?我不知道。这是我的php的示例:
<?php $con = mysql_connect("server.com","user","pswd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db", $con); $result = mysql_query("some command"); $row = mysql_fetch_array($result); mysql_close($con); ?>
<?php $con = mysql_connect("server.com","user","pswd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db", $con); $result = mysql_query("select count(1) FROM table"); $row = mysql_fetch_array($result); $total = $row[0]; echo "Total rows: " . $total; mysql_close($con); ?>