mysql_Connect error 3.2.1

mysql_Connect error 3.2.1

by Mark Fritz -
Number of replies: 10

I've rebuilt out server using Ubuntu 16.0.4 and migrated our old install from a SLES box.

I'm now unable to log in and get an mysql_connect() error due to that module being depricated in php7 but I cannot find anywhere where it is referenced in my config.

I've tried both mariadb and mysqli in the config.php file but it doesn't make a difference.


Debug trace is:


Exception - Call to undefined function mysql_connect()

More information about this error

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 878 of /enrol/database/lib.php: call to ADOConnection->Connect()
  • line 164 of /enrol/database/lib.php: call to enrol_database_plugin->db_init()
  • line 239 of /lib/enrollib.php: call to enrol_database_plugin->sync_user_enrolments()
  • line 478 of /lib/classes/session/manager.php: call to enrol_check_plugins()
  • line 4410 of /lib/moodlelib.php: call to core\session\manager::login_user()
  • line 195 of /login/index.php: call to complete_user_login()

Average of ratings: -
In reply to Mark Fritz

Re: mysql_Connect error 3.2.1

by Ken Task -
Picture of Particularly helpful Moodlers

Don't think using mariadb on a MySQL DB will work.   Stick wtih mysqli.

Is your login a manual account? (admin level).   Happen to remember what your account ID number was?

Did your site, under SuSE, use the DB for sessions? (SuSE site still up? check it's settings)

Assuming you can connect to the DB via command line with the DB user and DB password you have in the config.php file and that the import of the SQL dump from the SuSE site was completed without error:

Things to try:

Edit config.php file and add:

$CFG->dbsessions=0;

$CFG->siteadmins='2,[YOURACCOUNTIDNUMBER'';

ID 2 was the original/initially setup admin user that might still have 'admin' (that was default) as the username.

If you can query the DB from the command line one could use this query to find a row/records for a user with a known username (login)

mysql> select id,auth,email from mdl_user where username = '[YOURUSERNAME/login]';
Then use the ID number in the siteadmins line of config.php file.

'spirit of sharing', Ken

In reply to Ken Task

Re: mysql_Connect error 3.2.1

by Mark Fritz -

Hi Ken,

I reverted back to mysqli in the config.php with the same result.

As far as I can tell the database connection works as the website shows the correct theme and site customised text from the database. I can't figure out what might be overriding the mysqli directlive which I've been using since version 2.x.

Sessions are stored in the database, I actually cloned the SLES virtual machine to a new one in vmware and installed ubuntu onto the primary partition in the clone.

I then mounted the existing Moodle installation from the clone after installing all the php packages and extras listed in the wiki for 16.0.4.1 then did the upgrade.

I've gone back to the original SLES clone, restored last night database backup and will have to re-schedule a 3.2 upgrade to the next holiday period in April.

In reply to Mark Fritz

Re: mysql_Connect error 3.2.1

by Ken Task -
Picture of Particularly helpful Moodlers

Huh?

"...cloned the SLES virtual machine to a new one in vmware and installed ubuntu onto the primary partition in the clone."

So VMWare, guest OS SLES and in that Ubuntu!!!!

'then mounted the existing Moodle installation from the clone'

Lost me there.  What does that mean?

What shows to a web browser could be cached.   Try connecting to the DB from command line client.

'spirit of sharing', Ken

In reply to Mark Fritz

Re: mysql_Connect error 3.2.1

by Andrew Normore -

Hello, I have your fix. You will be very happy smile

Turns out, you have config.php set to use mysqli correctly, BUT the Moodle driver doesn't work correctly to select mysqli.

It still loads mysql driver to talk to your database. Because you're on PHP7, mysql_connect() has been removed from PHP.

Here's the fix:

https://github.com/moodle/moodle/compare/master...AndyNormore:patch-1

It's one simple link of code not working. I'm not sure if this is Moodle officially approved, but it will certainly limp you by. The bug is present in Moodle 3.3.1 and 3.3.2 I can confirm, not sure about others or when this bug is introduced.

In reply to Andrew Normore

Re: mysql_Connect error 3.2.1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

um - not quite... the debug log shows this is coming from /enrol/database/lib.php - which is the external enrolment database connection - not the connection to the Moodle database.

you need to go to admin > plugins > enrolments > External Database and change the settings on that page to use "mysqli" instead of "mysql" when connecting to your external database enrolment plugin. (not the setting in config.php)

Average of ratings: Useful (2)
In reply to Dan Marsden

Re: mysql_Connect error 3.2.1

by Andrew Normore -

Aha! That would certainly explain the problem!

I'll try this tomorrow and report back.

In reply to Andrew Normore

Re: mysql_Connect error 3.2.1

by Gisele Brugger -

Hello

I had the same problem

Moodle : 3.4
php : 7
mysql: 5.7.20

distro: debian 9

erro mysql connect

but I did not have authentication and in enroll via database 

when i change /enrol/database/lib.php

- $extdb = ADONewConnection($this->get_config('dbtype'));
+ $extdb = ADONewConnection($CFG->dbtype);


worked perfect


Thank you Andrew smile

In reply to Gisele Brugger

Re: mysql_Connect error 3.2.1

by Andrew Normore -

Turns out this is not the correct fix, and you need to actually go in to Moodle and configure the enrolment plugin itself... I forget how I did it now, but the code is behaving as expected.

In reply to Gisele Brugger

Re: mysql_Connect error 3.2.1

by Paul Flanders -

Have had the same issue today after migrating the a site from a server running PHP5.6 to PHP7.0 (Obviously mysql_connect is not longer supported in PHP7.0) but the error persisted even after altering the drive in config.php to "mysqli" meaning users could not login.


Although the config.php had the database driver set to "Mysqli" the Database enrolment plugin had its own driver setting which was set to "mysql" and overriding the config.php setting.


A quick search through the database led me to mdl_config_plugins and enrol_database : dbtype changing (Value) to mysqli and purging cache solved the login issue.


MDL-56933 talks about the issue a little more 


Paul

HowToMoodle