my sql best practice with php for counting rows

前端 未结 4 977
情书的邮戳
情书的邮戳 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:16

    $query="SELECT COUNT(id) FROM `table` WHERE `abc`='123'";
    $result = mysql_query($query);
    $count = mysql_fetch_row($result);
    

    This will work fast and light. Also, as Jack said in the comments above, you should use either MySQLi, or PDO, because the MySQL addon has been deprecated by PHP.

提交回复
热议问题