Heim > Fragen und Antworten > Hauptteil
pdo 怎么获取总列数
$cols=mysql_num_fields($result);//总列数
$total=mysql_num_rows($result);//总条数
用pdo 怎么写
PHP中文网2017-04-11 10:19:01
拼SQL
语句啊.COUNT()
try{
$pdo = new \PDO('mysql:dbname=test;host=localhost','root','');
$pdo->exec('SET NAMES utf8 ');
$stm = $pdo->query(' SELECT COUNT(*) FORM xxx ' );
$data = $stmt->fetch( PDO::FETCH_NUM);
}catch(PDOException $e)
{
die($e->getMessage());
}
高洛峰2017-04-11 10:19:01
$pdo = new PDO('mysql:test', 'root', '123456');
$count = $pdo->exec("select COUNT(1) FROM tables");