php method to determine how many data there are in the database: 1. Connect to the database; 2. Select the database to query; 3. Query how many data there are in the database through the "select count(*) from tablename" statement .
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How does php determine how many data there are in the database?
If the client connects to the database, one statement is OK.
select count(*) from tablename;
<?php $conn=mysql_connect('localhost','root','password');//连接数据库 mysql_select_db('databasename',$conn);//选择要查询的数据库 $sql="select count(*) from tablename";//SQL查询语句 if($result=mysql_query($sql,$conn)) { $aaa=mysql_fetch_row($result); echo $aaa[0]; //输出表里面总记录数 }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine how many data there are in the database in php. For more information, please follow other related articles on the PHP Chinese website!