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

藏色散人
Release: 2023-03-14 15:36:01
Original
2594 people have browsed it

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;
Copy after login
<?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]; //输出表里面总记录数
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!