Meaningless mysqli Errors

Photo of Greg Harvey
Tue, 2008-03-25 14:06By greg

I was installing a fresh copy of Drupal on Ubuntu this morning when I hit upon a problem. Half way through the installation script, Drupal kept throwing this at me:

PHP Warning: mysqli_error() [function.mysqli-error]: invalid object or resource mysqli

Followed by the equally useless:

Unable to connect to database server. The MySQL error was: .

Well thank you very much, Drupal. The message might as well just read "Something broke!"

I was on my hands and knees, half way through the haystack and hoping to stumble upon my needle, when I found this post on Drupal.org:
http://drupal.org/node/66783

Gribnif points out the error reporting in includes/database.mysqli.inc is crap. Currently, it looks like:

The MySQL error was: '. theme('placeholder', mysqli_error($connection)) .'.

If you change it thus, the mists will begin to clear:

The MySQL error was: '. theme('placeholder', mysqli_connect_error()) .'.

And guess what? It's just the same in includes/install.mysqli.inc too. One little change in the way Drupal currently reports errors, just as described, and suddenly you get a meaningful message from MySQL instead of just "pffft". I sincerely hope the core maintainers have looked at this thread. They will save people a lot of pain if they just change the way Drupal reports back from the mysqli.inc files.

In my case I'd simply forgotten to allow my database user to connect from 'localhost', but Drupal wasn't going to tell me that and I could've taken a very long time to realise! =(