php判断数据库有几条数据的方法:1、连接数据库;2、选择要查询的数据库;3、通过“select count(*) from tablename”语句查询数据库有几条数据即可。
本文操作环境:Windows7系统,PHP7.1版,Dell G3电脑。
php怎么判断数据库有几条数据?
如果是客户端连接数据库的话,一条语句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]; //输出表里面总记录数}