Whats the best way to get total # of records in a mysql table with php?

后端 未结 10 590
后悔当初
后悔当初 2021-01-12 05:51

Whats the most efficient way of selecting total number of records from a large table? Currently, Im simply doing

$result = mysql_query(\"SELECT id FROM table         


        
10条回答
  •  温柔的废话
    2021-01-12 06:01

    According to the MySQL documentation this is most efficient if you're using a MyISAM table (which is the most usual type of tables used):

    $result = mysql_query("SELECT COUNT(*) FROM table");
    

    Otherwise you should do as Wayne stated and be sure that the counted column is indexed.

提交回复
热议问题