2016-11-29 49 views
1

一个成员函数fetch_row()我试图获取MySQL查询行,但是越来越无法抓取行呼叫到布尔

Fatal error:Call to a member function fetch_row() on boolean.

我在做什么错在这里?

$select="visitor_country"; 
$startDate="2016-01-01"; 
$endDate="2016-12-31"; 
$groupBy="visitor_country"; 

$query=$connection->prepare("SELECT ?, COUNT(*) as count FROM `analytics`.`analytics` WHERE date BETWEEN ? AND ? GROUP BY ? ORDER BY count"); 
$query->bind_param('ssss',$select,$startDate,$endDate,$select); 
$query->execute(); 
$result=$query->store_result(); 
$row = $result->fetch_row(); 

$num_of_rows=count($row); 
echo $num_of_rows."<br>"; 
$query->close(); 
$connection->close(); 
+0

'store_result()'返回一个true/false,所以这并不奇怪。即使我删除store_result(),仍然看到手册http://php.net/manual/en/mysqli-stmt.store-result.php – Qirel

+0

@Qirel我仍然得到相同的错误。 – DAKSH

+0

我想你想要的是'$ result = $ query-> get_result()'而不是?这将其从MySQLi转换为MySQLi结果,您可以使用'fetch_row()'。 [get_result()']手册(http://php.net/manual/en/mysqli-stmt.get-result.php)。另外,MySQLi stmt和MySQLi结果都带有一个'num_rows'属性,所以不用'count($ row)'可以执行'$ query-> num_rows' – Qirel

回答

0

这里的答案

$query->bind_param('ssss',$select,$startDate,$endDate,$select); 
$query->execute(); 
$result = $query->get_result(); 
$row = $result->fetch_row(); 
$num_of_rows=count($row); 
echo $num_of_rows."<br>"; 
$query->close(); 
$connection->close();