要获取mysql 数据库表的多少条数据 怎么写。。。用pdo
回复讨论(解决方案)
$pdo = new PDO('127.0.0.1', username, password, dbname);$pdo->query("select count(*) from table_name");
直接用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应该是数组类型的数据!