Search code examples
phpmysqlelggwsod

Elgg white screen: undefined function Elgg\\mysql_connect()


I have an Elgg website running on Ubuntu 12.04 that abruptly started producing the white screen of death. No changes were made to any PHP files, all of which were working just moments before. This is the only error I get in the apache error.log:

[Thu Jul 23 09:45:49.672038 2015] [:error] [pid 6905] [client 127.0.0.1:53280] PHP Fatal error:  Call to undefined function Elgg\\mysql_connect() in /var/www/my-website/engine/classes/Elgg/Database.php on line 144

Apache2 can load HTML and PHP pages and I can log into MySQL from the command line. I've restarted apache2 and mysql. PHP, AFAIK, is at the most recent version. I have restarted my computer and installed the most recent updates. The following test page produces nothing that seems out of the ordinary to the untrained eye:

<?php
echo "Test!";
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

phpinfo(); 
exit(); 

?>

This post makes me think that maybe an update ran and broke the PHP / mysql connection, but I can't confirm that. Simpy put, I'm stumped. Given that the error isundefined function Elgg\\mysql_connect(), I presume something's gone awry at a configuration level, but I have no idea how to fix it nor any firm hypotheses as to what might've caused it. What should I try next?


Solution

  • It is most likely a namespacing issue. PHP is assuming that its own native mysql api is a function declared inside the Elgg\ namespace. So, go to 'Database.php' and on line 144 change:

    mysql_connect(); to \mysql_connect();

    The \ backslash will instruct php this function exists outside the Elgg\ namespace, or within the global scope.

    You'll probably encounter similar issues which you must solve using the same method as described above.