php统计数据库总数 php统计数据库数据

php怎么统计mysql表里有多少数据,怎么把比如user里面的数据全部显示出来$conn
=
mysql_connect('localhost','root','123');
mysql_select_db('db_name');
//数据库名
mysql_query('set
names
utf8',$conn);
#$res
=
mysql_query('select
count(*)
from
user',$conn);
//统计user表里总共有多少条数据
#$res
=
mysql_query('select
*
from
user',$conn);
//把user里面的数据全部显示出来
$arr
=
array();
while($data
=
mysql_fetch_assoc($res))
{
$arr[]
=
$data;
}
print_r($arr);
可以依次把上面查询语句前面的注释去掉查看效果
如何用PHP统计mysql数据表里指定字段的内容的总数mysql_connect("localhost","root","123456") or
die("打开数据库服务器失败!");//连接数据库
mysql_select_db("a") or
die("打开数据库a失败!");//打开数据库,a为数据库名
$sql = "select id from b";//id为字段名,b为表名
$result=mysql_query($sql);
if(mysql_query($sql))//判断$sql语句是否执行
{
$num=mysql_num_rows($result);//取得包含id字段记录的行数
echo "一共有".$num."个id"; }思想就是:根据含有ID的记录(数据库里一行内容称为一条记录)条数来确定ID的个数
PHP+MySQL如何统计数据库容量?要想知道每个数据库的大小的话php统计数据库总数,步骤如下:
1、进入information_schema
数据库(存放了其php统计数据库总数他的数据库的信息)
use
information_schema;
2、查询所有数据的大?。?
select
concat(round(sum(data_length/1024/1024),2),'MB')
as
data
from
tables;
3、查看指定数据库的大?。?
比如查看数据库home的大小
select
concat(round(sum(data_length/1024/1024),2),'MB')
as
data
from
tables
where
table_schema='home';
4、查看指定数据库的某个表的大小
比如查看数据库home中
members
表的大小
select
concat(round(sum(data_length/1024/1024),2),'MB')
as
data
from
tables
where
table_schema='home'
and
table_name='members';
php连接数据库服务器 , 然后选择使用的数据库名称为information_schema,然后执行查询就行了 。看php统计数据库总数你问的这个问题应该不会不知道用php访问数据库吧 。
如果php统计数据库总数你权限不够的话可能只能对特定的数据库的信息进行查询 。
php如何用foreach遍历不同数据库最后统计总数?php如何用foreach遍历不同数据库最后统计总数?
下面适用所有一维数组.
$i=0;
$arr_n=count($ar)-1;
foreach($ar as $f){
if($arr_n!=$i){
echo $f."br";
}
$i++;
}
类似于
$arr_n=count($ar);
for($i=0;$i$arr_n-1;$i++){
echo $ar[$i]."br";
}
php实现数据库统计用sql查询语句就能实现 例如 你的表名叫student里面的性别字段是sex
查询男生有多少人
select count(*) as c from student where sex='男'
查询女生有多少人
select count(*) as c from student where sex='女'
然后在php里用MySQL_fetch_row就能得出结果了
php使用mysql怎么查询数据库已经有多少条数据php使用mysql查询数据库已经有多少条数据使用sql的count函数实现 。
示例代码如下:
?php
//数据库连接
$conn=mysql_connect("localhost","root","root");
if(!$conn){
die("对不起,数据库连接失败! ").mysql_errno();
}
//选择数据库
mysql_select_db("testdb");
//sql语句

推荐阅读