I have Drupal 7.21 installation based on 2 web servers (Red Hat Linux, Apache, PHP, MySQL, APC). Servers have same configuration, code base and work with same database. I get this error from time to time on one (not both) server at the same time:
[Thu Jun 20 13:18:48 2013] [error] [client XXX.XX.XX.XX] PHP Fatal error: Call to a member function getKey() on a non-object in /web/20130607-0825/includes/database/query.inc on line 341
Investigation lead me to this part of code:

  public function __construct(DatabaseConnection $connection, $options) {
    $this->uniqueIdentifier = uniqid('', TRUE);

    $this->connection = $connection;
    $this->connectionKey = $this->connection->getKey();
    $this->connectionTarget = $this->connection->getTarget();

    $this->queryOptions = $options;
  }

where $connection is NULL for some reason. I can't debug since it is production, but i have printed stack trace - and i see that error happens during bootstrap of variables, db_insert while setting lock in semaphore table.

This problem bothers me for about 2-3 weeks and i have no idea how to debug/investigate it. It is flexible, i can't reproduce it on demand. It stops when i restart httpd service. I tried to disable APC cache, but problem stays. I can connect to database via mysql client normally when errors appear.
How this could happen on servers with same config and code? I will appreciate any help.

Comments

shlapa’s picture

Issue summary: View changes

update

NVaissaud’s picture

I encounter the same problem on two websites, both hosted on same server.
I can't reproduce it on demand aswell.
Did you find a solution or get any other clue?

Thanks.

shlapa’s picture

Hi.

I have not found the reason, but in our case updating PHP + Apache + APC + PDO to the latest versions from Red Hat repository helped. Probably some bug in PHP.

lahoosascoots’s picture

I saw this issue on a client site. Memcache ended up being the cause. Flushed memcache and all was well.

beefheartfan’s picture

I have been experiencing a similar thing for several weeks.
Drupal 7.36, PHP 5.3.3.
I get this error intermittently:
PHP Fatal error: Call to a member function getKey() on a non-object in /includes/database/query.inc on line 334

We don't use memcache on the site.

Any help you can provide would be very much appreciated!

Version: 7.21 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.