PHP 致命错误:在非对象上调用成员函数 num_rows()

发布于 2024-12-25 05:01:40 字数 1041 浏览 4 评论 0原文

我正在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

聊慰 2025-01-01 05:01:40

检查以确保生产中的数据库与本地环境具有相同的结构。

从 phpMyAdmin 或您最喜欢的 MySQL GUI 客户端执行以下步骤:

  1. 选择您的 ExpressionEngine 数据库
  2. 执行以下 SQL 语句:
  3. DESCRIBE exp_freeform_fields;
  4. 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:

  1. Select your ExpressionEngine database
  2. Execute the following SQL Statements:
  3. DESCRIBE exp_freeform_fields;
  4. SELECT name FROM exp_freeform_fields;

Compare the results from your Local MySQL Database to your Production MySQL Database.

°如果伤别离去 2025-01-01 05:01:40

您可能在生产系统和本地系统上获得了不同的数据库内容,因此该语句在生产系统上失败并产生错误。

您应该尝试在 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.

挖鼻大婶 2025-01-01 05:01:40

看来您的 $query 对象没有有效的连接。控制您的用户名、密码和数据库配置。

Seems that your $query object has no valid connection. Control your username, password and database configuration.

街道布景 2025-01-01 05:01:40

config.phpdatabase.php 中启用调试以查看详细的错误消息:

/system/expressionengine/config/config.php

$config['debug'] = '1';

/system/expressionengine/config/database.php

$db['expressionengine']['db_debug'] = TRUE;

验证

  • 您的 MySQL 数据库凭据
  • 检查 Apache 和/或 PHP 的 error_log

希望这些步骤可以让您更深入地了解您的问题。

Enable debugging in your config.php and database.php to see detailed error messages:

/system/expressionengine/config/config.php

$config['debug'] = '1';

/system/expressionengine/config/database.php

$db['expressionengine']['db_debug'] = TRUE;

It also wouldn't hurt to:

  • Verify your MySQL database credentials
  • Check Apache's and/or PHP's error_log

Hopefully, these steps will allow you to get more insight into your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文