为什么这在phpMyAdmin中有效,而在php脚本中无效


Why does this work in phpMyAdmin but not in php script?

当我将以下内容粘贴到phpmyadmin中时,它正确地返回了719条记录。

SET SQL_BIG_SELECTS=1;
select lc.townshipnumber, lc.sectionlegal, sum(fm.acres) FROM lc join fm on 
lc.parcelnumber = fm.parcelnumber join fp on fm.type=fp.soiltype join fc on 
(fp.soilgroup=fc.soilgroup and fp.soilclass=fc.soilclass) where townshipnumber 
<=20 and sectionlegal<=36 and sectionlegal>=1 and fm.year = '2013' group by 
townshipnumber, sectionlegal";

当我把它粘贴到php脚本中时,我使用$query = (*the select statement from above*),然后使用$result = $mysqli->query($query) or die ("Errorr in query: $query. ".mysqli_error());

php脚本中的下一行显示了找到的记录,但对于这个特定的查询,屏幕仍然是空的。

$records_found=mysqli_num_rows($result);
echo $records_found.' Records Found<br /><br />';

您将结果作为一个对象,但实际上还没有对它做任何有用的事情。您可以将它制作成一个数组,然后循环使用它来获得结果。

<?php 
     // Save the query results in an array, which you can then loop through
     var_dump(mysqli_fetch_array($result));