Php 获取所选行的错误计数
结果是-1 手动检查表共20行-没有这样的行具有cas=$a。。。所以结果应该是0。试试这个:Php 获取所选行的错误计数,php,mysql,count,Php,Mysql,Count,结果是-1 手动检查表共20行-没有这样的行具有cas=$a。。。所以结果应该是0。试试这个: function c_save( $a, $status, $b ) { global $db; $st = $db->query( "select count(id) from steps where cas = '" . $a . "' and status = '" . $status . "' and title = '" . $b . "'" ); $count
function c_save( $a, $status, $b ) {
global $db;
$st = $db->query( "select count(id) from steps where cas = '" . $a . "' and status = '" . $status . "' and title = '" . $b . "'" );
$count = $st->rowCount(); echo $count;
}
您正在查询级别执行计数。查询的结果是一行,可能包含20个字符。
如果您想要获得记录的数量,您可以只获取查询返回的值,或者不在sql中计数,以获得完整的结果集,并让php进行计数 查询将返回一行,该行包含匹配行的计数。如果改为将查询更改为SELECT*…,并获取$st->rowCount,则它应该返回0。
function c_save($a, $status, $b){
global $db;
$st = $db->query("select id from steps where cas = '" . $a . "' and status = '" . $status . "' and title = '" . $b . "'");
$count = $st->rowCount();
echo $count;
}