我试图了解mysqli扩展名,并做了谷歌,但除了php.net这方面的信息很少。
现在毕竟这是我想要实现的MySQL扩展,如下所示:
// MYSQL STYLE OF fetching array, query limit and perform total row count all at once
$sql = "SELECT SQL_CALC_FOUND_ROWS *, post.id as pid, bla bla FROM account ORDER BY pid ASC". $eb["array"]['querylimit'];
$result = mysql_query($sql, $eb["con"]);
$TotalRcount = mysql_fetch_row(mysql_query("SELECT FOUND_ROWS()"));
// Performing record count [current]
// $RecordCount = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
// read columns
}
用mysqli我怎么能做到这一点?我肯定我错过了很多事情。请以示例的方式帮助我,以实现我的目标。
最佳答案
使用mysqli,您可以通过以下方式进行操作(假设mysqli对象已创建-您也可以使用procedure methods,稍有不同):
$sql = "SELECT SQL_CALC_FOUND_ROWS *, post.id as pid, bla bla
FROM account ORDER BY pid ASC". $eb["array"]['querylimit'];
$result = $mysqli->query($sql);
$TotalRcount = $result->num_rows;
while($row=$result->fetch_assoc()){
$col1 = $row['col1']; // col1 is a placeholder for whatever column you are reading
//read columns
}
关于mysql - mysql-如何使用mysqli获取总行数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14682448/