Home  >  Article  >  Backend Development  >  How to determine how many data there are in the database in php

How to determine how many data there are in the database in php

藏色散人
藏色散人Original
2021-12-27 09:38:212637browse

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 .

How to determine how many data there are in the database in php

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(&#39;localhost&#39;,&#39;root&#39;,&#39;password&#39;);//连接数据库
mysql_select_db(&#39;databasename&#39;,$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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn