Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top