
正文
关于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);
可以依次把上面查询语句前面的注释去掉查看效果
相关问答
Q1: php实现数据库统计
用sql查询语句就能实现 例如 你的表名叫student 里面的性别字段是sex
查询男生有多少人
select count(*) as c from student where sex='男'
查询女生有多少人
select count(*) as c from student where sex='女'
然后在php里用MySQL_fetch_row就能得出结果了
Q2: php thinkphp 怎么统计数据库数据的条数
其实我感觉你这个逻辑没问题,代码有点问题,我是这么认为的,代码应该是这样
$idzhi = rand(0,表中数据条数);
$data = $data['id']; // 我不明白你这里是什么意思
$arr = $m-where($data = $idzhi)-limit(8) -select();
不过我总感觉上面的有问题
$idzhi = rand(0,表中数据条数);
$arr = $m-where("id = $idzhi")-limit(8) -select();
不对的话就试试这个,我个人觉得这样是对的,不明白你那个$data['id'];是干嘛用的
Q3: PHP+MySQL如何统计数据库容量?
要想知道每个数据库的大小的话,步骤如下:
1、进入information_schema
数据库(存放了其他的数据库的信息)
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显示数据库统计数的信息别忘了在本站进行查找喔。





