PHP 致命错误:在非对象上调用成员函数 num_rows()
我正在将 MySQL 与 ExpressionEngine 2.2.1 结合使用。此版本的 ExpressionEngine 自动附带一个查询模块,我用它来过滤和显示来自名为 Freeform 的模块的条目结果。我使用的是 Freeform 版本 3.1.1。所有这些元素都可以很好地协同工作,并在我的本地设置上显示所需的结果。但是,当我将代码推送到生产环境时,我收到此错误:
致命错误:在 /var/www/vhosts/xxxxxxxxx.com/systemxxx/expressionengine/ 中的非对象上调用成员函数 num_rows() module/query/mod.query.php 位于第 183 行
这是从 mod.query.php 第 183 行开始的这部分代码(我没有编写此 php,也从未编写过php,这已经包含在我正在处理的网站中。):
183 if ($query->num_rows() == 0)
184 {
185 return $this->return_data = $this->EE->TMPL->no_results();
186 }
这是我在 HTML 模板中使用查询模块的方式:
{exp:query sql="SELECT first_name, last_name, email, city FROM exp_freeform_entries WHERE city = 'New York'"}
<tr>
<td>{first_name}</td>
<td>{last_name}</td>
<td>{email}</td>
<td>{city}</td>
</tr>
{/exp:query}
有谁知道为什么会发生此错误?为什么它会发生在生产中而不是本地?
任何帮助将不胜感激!
I am working with MySQL in conjunction with ExpressionEngine 2.2.1. This version of ExpressionEngine automatically comes with a Query Module, which I am using to filter and display entry results from a module called Freeform. I am using Freeform version 3.1.1. All of these elements are working well together and displaying the desired results on my local setup. However when I push my code to production, I am receiving this error:
Fatal error: Call to a member function num_rows() on a non-object in /var/www/vhosts/xxxxxxxxx.com/systemxxx/expressionengine/modules/query/mod.query.php on line 183
Here is this section of the code beginning on line 183 of mod.query.php (I did not code this php, nor have I ever coded php, this was already included with the site that I am working on.):
183 if ($query->num_rows() == 0)
184 {
185 return $this->return_data = $this->EE->TMPL->no_results();
186 }
Here is how I am using the Query Module in my HTML Template:
{exp:query sql="SELECT first_name, last_name, email, city FROM exp_freeform_entries WHERE city = 'New York'"}
<tr>
<td>{first_name}</td>
<td>{last_name}</td>
<td>{email}</td>
<td>{city}</td>
</tr>
{/exp:query}
Does anyone know why this error is occurring? Why would it be occurring on production but not locally?
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查以确保生产中的数据库与本地环境具有相同的结构。
从 phpMyAdmin 或您最喜欢的 MySQL GUI 客户端执行以下步骤:
DESCRIBE exp_freeform_fields;
SELECT name FROM exp_freeform_fields;
比较您的结果本地 MySQL 数据库到生产 MySQL 数据库。
Check to make sure the database in Production has the same structure as your Local environment.
Perform the following steps from phpMyAdmin or your favorite MySQL GUI client:
DESCRIBE exp_freeform_fields;
SELECT name FROM exp_freeform_fields;
Compare the results from your Local MySQL Database to your Production MySQL Database.
您可能在生产系统和本地系统上获得了不同的数据库内容,因此该语句在生产系统上失败并产生错误。
您应该尝试在 phpmyadmin 或类似的东西中执行该语句,看看您的 sql 语句是否没有错误并且与命名没有任何冲突。
You probably got different database content on production and local systems so the statement fails on the production system producing an error.
You should try executing the statement in phpmyadmin or something like that to see if your sql statement is error-free and doesn't have any conflicts with naming.
看来您的 $query 对象没有有效的连接。控制您的用户名、密码和数据库配置。
Seems that your $query object has no valid connection. Control your username, password and database configuration.
在
config.php
和database.php
中启用调试以查看详细的错误消息:/system/expressionengine/config/config.php
/system/expressionengine/config/database.php
验证
error_log
希望这些步骤可以让您更深入地了解您的问题。
Enable debugging in your
config.php
anddatabase.php
to see detailed error messages:/system/expressionengine/config/config.php
/system/expressionengine/config/database.php
It also wouldn't hurt to:
error_log
Hopefully, these steps will allow you to get more insight into your problem.