本文介绍了php/mysql 不计算表中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行此查询:

I am trying to run this Query:

$stmt = $conn->prepare("SELECT COUNT(*) as a from session ");
$stmt->execute(array());
$records = $stmt->fetch();
echo '- '.$result["a"];

但它只是显示:

-

就其本身而言,没有记录数,我知道有行,因为当我运行时

on its own, with no number of records, i know there is rows because when i run

SELECT COUNT(*) from `session` as a

在 PHPMyAdmin 中,它显示列 a 中的所有行

in PHPMyAdmin it shows all the rows there in the column a

为什么这个查询不起作用?

why would this query not work?

推荐答案

试试这个

$stmt = $conn->prepare("SELECT COUNT(*) as cnt from `session` ");
$stmt->execute(array());
$records = $stmt->fetch();
echo '- '.$records["cnt"];

这篇关于php/mysql 不计算表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 01:21