Upgrade to 1.8.0 fails - can't connect to mysql

Bug #1247715 reported by henrythemouse
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
High
Robert Lyon
1.8
Fix Released
High
Unassigned
1.9
Fix Released
High
Robert Lyon

Bug Description

After upgrading to 1.8.0 I couldn't open the admin/upgrade.php page. The error displayed stated that mahara could not connect to the mysql db. Running on Ubuntu LTS Server.

After some poking around I managed to get things running by altering the code in init.php.

The new code read:

    // Transform $CFG->dbtype into the name of the ADODB driver we will use
    if (is_postgres()) {
        $CFG->dbtype = 'postgres7';
    }
    else if (is_mysql()) {
        // If they have mysqli, use it. Otherwise, fall back to the older "mysql" extension.
        if (extension_loaded('mysqli')) {
            $CFG->dbtype = 'mysqli';
        }
        else {
            $CFG->dbtype = 'mysql';
        }
    }

I replace this with:

    // Transform $CFG->dbtype into the name of the ADODB driver we will use
    if (is_postgres()) {
        $CFG->dbtype = 'postgres7';
    }
    else if (is_mysql()) {
        // If they have mysqli, use it. Otherwise, fall back to the older "mysql" extension.
        //if (extension_loaded('mysqli')) {
        // $CFG->dbtype = 'mysqli';
        //}
        //else {
        // $CFG->dbtype = 'mysql';
        //}
        $CFG->dbtype = 'mysql';
    }

I also receive the error:

The mysqli PHP extension is not installed on your server. Thus, Mahara is falling back to the deprecated original mysql PHP extension. We recommend installing mysqli. Trouble is that fallback doesn't seem to be working at all.

Fact is mysqli is included with php5-mysql in ubuntu. Mahara doesn't seem to see that. Maybe the code that is suppose to detect that in init.php blocks connection to the server, stopping mahara from running at all.

This does not happen in 1.7.x.

Revision history for this message
Robert Lyon (robertl-9) wrote :

Hi henrythemouse,

Yes I've just run into the same problem - there does seem to be an issue upgrading a site that was using a mysql connection to 1.8 that wants to use mysqli

I'll take a look into this

Cheers

Robert

Changed in mahara:
status: New → Confirmed
importance: Undecided → High
assignee: nobody → Robert Lyon (robertl-9)
Revision history for this message
Robert Lyon (robertl-9) wrote :

The error I received was:
mysqli error: [2005: Unknown MySQL server host '[hostname]:3306' (2)] in PCONNECT([hostname]:3306, 'mahara', '****', maharadev)

where [hostname] = name of host

Revision history for this message
Robert Lyon (robertl-9) wrote :

It looks like this could be the problem:
http://stackoverflow.com/questions/6484935/mysqli-unknow-server-host

the setting of the port number is breaking things for mysqli

Aaron Wells (u-aaronw)
description: updated
Changed in mahara:
milestone: none → 1.8.1
Revision history for this message
Aaron Wells (u-aaronw) wrote :

To add some additional info about the link that Robert just posted, the issue is that, if you specifically supply a $CFG->dbport value, then Mahara appends that to the end of your $CFG->dbhost value before sending it to mysqli_real_connect(), like "localhost:3306". The problem is that mysqli doesn't support that. Instead, we need to supply the port number as a separate argument (the fifth) to mysqli_real_connect(). Implementation-wise, in order to do that in ADODB, we need to manually set the "$this->port" for the ADODB_mysqli object.

The workaround, is that if you're using port 3306 (which is the default for MySQL), simply remove the $cfg->dbport line from your config.php file.

If you are not using port 3306, then you'll need to patch the software to fix it.

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Okay, here's a patch that should resolve the issue:

https://reviews.mahara.org/2688

Revision history for this message
henrythemouse (witscher) wrote : Re: [Bug 1247715] Re: Upgrade to 1.8.0 fails - can't connect to mysql

Works for me.

Thank you
Gary

Quoting Aaron Wells <email address hidden>:

> Okay, here's a patch that should resolve the issue:
>
> https://reviews.mahara.org/2688
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1247715
>
> Title:
> Upgrade to 1.8.0 fails - can't connect to mysql
>
> Status in Mahara ePortfolio:
> Confirmed
>
> Bug description:
> After upgrading to 1.8.0 I couldn't open the admin/upgrade.php page.
> The error displayed stated that mahara could not connect to the mysql
> db. Running on Ubuntu LTS Server.
>
> After some poking around I managed to get things running by altering
> the code in init.php.
>
> The new code read:
>
>     // Transform $CFG->dbtype into the name of the ADODB driver we will use
>     if (is_postgres()) {
>         $CFG->dbtype = 'postgres7';
>     }
>     else if (is_mysql()) {
>         // If they have mysqli, use it. Otherwise, fall back to
> the older "mysql" extension.
>         if (extension_loaded('mysqli')) {
>             $CFG->dbtype = 'mysqli';
>         }
>         else {
>             $CFG->dbtype = 'mysql';
>         }
>     }
>
> I replace this with:
>
>     // Transform $CFG->dbtype into the name of the ADODB driver we will use
>     if (is_postgres()) {
>         $CFG->dbtype = 'postgres7';
>     }
>     else if (is_mysql()) {
>         // If they have mysqli, use it. Otherwise, fall back to
> the older "mysql" extension.
>         //if (extension_loaded('mysqli')) {
>         // $CFG->dbtype = 'mysqli';
>         //}
>         //else {
>         // $CFG->dbtype = 'mysql';
>         //}
>         $CFG->dbtype = 'mysql';
>     }
>
> I also receive the error:
>
> The mysqli PHP extension is not installed on your server. Thus, Mahara
> is falling back to the deprecated original mysql PHP extension. We
> recommend installing mysqli. Trouble is that fallback doesn't seem to
> be working at all.
>
> Fact is mysqli is included with php5-mysql in ubuntu. Mahara doesn't
> seem to see that. Maybe the code that is suppose to detect that in
> init.php blocks connection to the server, stopping mahara from running
> at all.
>
> This does not happen in 1.7.x.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/mahara/+bug/1247715/+subscriptions

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/2688
Committed: http://gitorious.org/mahara/mahara/commit/7abb6793af0d42efc2059ba4651cd596b441e463
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit 7abb6793af0d42efc2059ba4651cd596b441e463
Author: Aaron Wells <email address hidden>
Date: Wed Nov 6 15:07:55 2013 +1300

Pass the $CFG->dbport to ADODB separately from the hostname

Bug1247715: The mysqli driver doesn't support sending "hostname:port" but it and
the others do support setting a $db->port field manually.

Change-Id: I4f145d8a424717dbb9bed53f78cfc01f521c9dae

Son Nguyen (ngson2000)
Changed in mahara:
status: Confirmed → Fix Committed
Revision history for this message
Aaron Wells (u-aaronw) wrote :
Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/2816
Committed: http://gitorious.org/mahara/mahara/commit/d5ab56b129f91829734e700c273ecc0ff3b8327b
Submitter: Aaron Wells (<email address hidden>)
Branch: 1.8_STABLE

commit d5ab56b129f91829734e700c273ecc0ff3b8327b
Author: Aaron Wells <email address hidden>
Date: Wed Nov 6 15:07:55 2013 +1300

Pass the $CFG->dbport to ADODB separately from the hostname

Bug1247715: The mysqli driver doesn't support sending "hostname:port" but it and
the others do support setting a $db->port field manually.

Change-Id: I4f145d8a424717dbb9bed53f78cfc01f521c9dae

Aaron Wells (u-aaronw)
Changed in mahara:
status: Fix Committed → Fix Released
Robert Lyon (robertl-9)
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.