【问题标题】:Why does this work in phpMyAdmin but not in php script?为什么这在 phpMyAdmin 中有效,但在 php 脚本中无效?
【发布时间】:2014-11-08 02:48:44
【问题描述】:

当我将以下内容粘贴到 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-&gt;query($query) or die ("Errorr in query: $query. ".mysqli_error());

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

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

【问题讨论】:

  • SET SQL_BIG_SELECTS=1,在你的主查询之前设置它,它会起作用.. PHP 不会同时执行这两个命令。
  • 您不能使用query() 一次运行多个查询。单独执行或使用mysqli_multi_query
  • 问题已经演变。我将整个 php 程序减少到 2 行 echo "show this";设置 SQL_BIG_SELECTS=1;除非我注释掉第二行,否则我只会得到一个空屏幕,然后屏幕上就会出现“显示这个”字样。我正在使用 HostMonster。我真的以为我以前可以使用 sql_big_selects,但现在不行了。下一步我可能会联系 HostMonster。

标签: php mysqli phpmyadmin


【解决方案1】:

您将结果作为一个对象,但实际上您还没有对它做任何有用的事情。你可以把它做成一个数组,循环遍历得到结果。

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

【讨论】:

  • 我稍后在我的代码中使用 $row = mysqli_fetch_row($result) 然后我进一步处理它。问题是它甚至在到达应该显示找到的记录数的行之前就挂在空屏幕上。如果它只是说“找到 719 条记录”,我会没事的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-17
  • 1970-01-01
  • 1970-01-01
  • 2014-10-17
  • 2012-11-06
相关资源
最近更新 更多