Call to undefined function mysql_connect after upgrade to Moodle 3.6

Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Albert R. -
Number of replies: 8

First of all, I've done my research and the solutions I've found haven't worked for me.

I've just upgraded a Moodle 3.2 site to Moodle 3.6.1. The upgrade process has seemingly gone fine, however I can't log into the site, I get the following error:

Exception - Call to undefined function mysql_connect()

The old site used to run on PHP 5.6, but I've upgraded the server's PHP 7.2 and installed all the required modules. I'm aware that on PHP 7 mysql has been deprecated, and following indications found online I've changed the dbtype to mysqli before the upgrade, as explained here: https://moodle.org/mod/forum/discuss.php?d=370774. I've made this change both in the site's admin area for the external enrolment plugin (before the Moodle upgrade) and in the database (after the upgrade).

After doing the Moodle upgrade, the site loads fine, until I try to login, when I get the aforementioned error. The site uses external database authentication for students, but the admin user is in the same database as Moodle (not in the external one).

Any ideas of how I can fix this? Looks like the error comes from Moodle insisting in using mysql instead of mysqli, but I don't know what else to change to prevent that... I've also purged caches and restarted db services to no avail.

This is the debug output when trying to login as an admin:

Debug info: 
Error code: generalexceptionmessage
Stack trace: 
line 461 of /lib/adodb/drivers/adodb-mysql.inc.php: Error thrown
line 492 of /lib/adodb/drivers/adodb-mysql.inc.php: call to ADODB_mysql->_connect()
line 667 of /lib/adodb/adodb.inc.php: call to ADODB_mysql->_nconnect()
line 867 of /enrol/database/lib.php: call to ADOConnection->Connect()
line 144 of /enrol/database/lib.php: call to enrol_database_plugin->db_init()
line 245 of /lib/enrollib.php: call to enrol_database_plugin->sync_user_enrolments()
line 486 of /lib/classes/session/manager.php: call to enrol_check_plugins()
line 4528 of /lib/moodlelib.php: call to core\session\manager::login_user()
line 199 of /login/index.php: call to complete_user_login()
EDIT - Clarification of what I've tried already:


1. $CFG->dbtype = 'mysqli'; in config.php

2. In DB table mdl_config_plugins: enrol_database->dbtype set to mysqli

3. In Site Admin -> Plugins -> Authentication -> External database -> DB Type set to mysqli

Average of ratings: -
In reply to Albert R.

Re: Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

"sync_user_enrolments"

I suspect you have an enrolment plugin enabled that's causing this rather than core moodle. 

Are you, for example, using external database enrolment? If so, has that been configured to use the old mysql functions?

In reply to Howard Miller

Re: Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Albert R. -

I do use external database enrolment, but that's been set up to use mysqli and not mysql

In reply to Albert R.

Re: Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Too much of a coincidence - prove it wink

The error trace says otherwise. 

In reply to Howard Miller

Re: Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello Everyone,
here is a similar thread: https://moodle.org/mod/forum/discuss.php?d=380433 and how to debug the actual setting, https://moodle.org/mod/forum/discuss.php?d=380433#p1534009.

If no one will ever try to show the actual setting, no one will be able to go further in helping you, eventually tracking the real issue behind the "evidence".

HTH,
Matteo

Average of ratings: Useful (1)
In reply to Howard Miller

Re: Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Albert R. -

Found the problem, see solution below

In reply to Albert R.

Re: Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Albert R. -
SOLUTION

For some reason, the auth_db setting in the external authentication plugin (not the enrolment one, which is the one I had checked based on that post I mentioned) was showing as mysqli in the Site Admin settings, but in the database it still showed as mysql.


The solution was to manually change the following row in the database to reflect mysqli instead of mysql:


Table: mdl_config_plugins

Rowauth_db -> type set to mysqli


After doing this login was working fine again smile

Average of ratings: Useful (2)
In reply to Albert R.

Re: Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Albert,
thanks for your follow up!
Could you give us more details about your system? E.g. a plain Moodle installation i.e. w/ no external cache store but the default file system, just using an external DB auth and enrol setup and some 3rd party plug-ins.

It looks like some weird issue - stale Moodle cache entry? - is happening on updating that setting on the external DB authentication plug-in but if we want to file an issue into the Tracker, we should define how to replicate it with a list of plain steps to identify if that issue arises when you update the Moodle code from a previous version that requires a PHP migration plan or just changing the DB Type version, regardless if it's required due to a PHP version update.

Or, at the time of your first post did you simply miss that setting i.e. you've updated just the external DB enroll setting and not the external DB auth one?

TIA,
Matteo

In reply to Matteo Scaramuccia

Re: Call to undefined function mysql_connect after upgrade to Moodle 3.6

by Albert R. -

Hi Matteo,

My system is pretty much what you mention in your example, a plain Moodle installation (3.6 after the upgrade coming from 3.2) with external dabatase enrolment and external database authentication, and just a couple fo 3rd party plugins.

What happened at first was that I had only changed the external database enrolment dbtype setting to mysqli, leaving the external database authentication auth_db setting to mysql since that wasn't mentioned in the post I linked and I didn't think of it.

That was giving the errors I mentioned, so I started from scratch (reverted my installation to Moodle 3.2 again from a backup). This time I did change both settings to mysqli (enrolment and authentication) before doing the upgrade, but still got the error. I decided to check for both values in the database and they still showed as mysql, so I corrected them manually and everything worked.

It does sound like a weird issue but oh well, at least it's fixed now smile

Average of ratings: Useful (1)