my sql best practice with php for counting rows

前端 未结 4 971
情书的邮戳
情书的邮戳 2021-01-28 18:31

1) Count record:

//Connect to mysql server
$link = mysql_connect(HOST, USER, PASSWORD);
if(!$link) {
    die(\'Could not connect to server: \' . mysql_error());
         


        
4条回答
  •  情书的邮戳
    2021-01-28 19:01

    When you only need the count the record, you should use COUNT() function of mysql, instead of load all of the records.

    $query="SELECT COUNT(*) AS num FROM `table` WHERE `abc`='123'";
    

    Second, use PDO instead of mysql_ functions.

提交回复
热议问题