Home > Backend Development > PHP Tutorial > mysql返回多少数据

mysql返回多少数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:05:09
Original
882 people have browsed it

要获取mysql 数据库表的多少条数据 怎么写。。。用pdo


回复讨论(解决方案)

$pdo = new PDO('127.0.0.1', username, password, dbname);$pdo->query("select count(*) from table_name");
Copy after login


直接用count(*)执行sql就行吧

关键是没看懂你的意思。你可以再把需求描述的详细一点。什么多少条?

$pdo->query("select count(*) from table_name"); 怎么获取返回值???有几条数据。。

$r = $pdo->query("select count(*) as cnt from table_name")->fetch(PDO::FETCH_ASSOC);
echo $r['cnt'];

$r = $pdo->query("select count(*) from table_name")->fetch(PDO::FETCH_NUM);
echo $r['cnt'];

php5.4.x 还可以写作
echo $pdo->query("select count(*) as cnt from table_name")->fetch(PDO::FETCH_ASSOC)['cnt'];

echo $pdo->query("select count(*) from table_name")->fetch(PDO::FETCH_NUM)[0];

$pdo->query("select count(*) from table_name"); 怎么获取返回值???有几条数据。。

用一个变量去接收,即
$data = $pdo->query("select count(*) from table_name");
$data应该是数组类型的数据!

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