Welcome Guest, Not a member yet? Register   Sign In
A Database Error Occurred, Unable to connect to your database server using the provided settings.
#1

[eluser]pat242[/eluser]
I get this error:

A Database Error Occurred
Unable to connect to your database server using the provided settings.

It has happened twice on clean installs of: PYROCMS
and again on a different application I'm trying. Could it be my hosting?

my settings:
Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "bari_user";
$db['default']['password'] = "pass";
$db['default']['database'] = "bari_db";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

I have tried the following:

Did test connect from an independent file and it connected:
Code:
<?php
$link = mysql_connect('localhost', 'bari_user', 'pass');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

Database is loaded:
Code:
$autoload['libraries'] = array('database');

changed the quotes:
Quote:
Code:
$db['default']['hostname'] =  "mysql.myhost.com";

Causes the error while:
Code:
$db['default']['hostname'] =  'mysql.myhost.com';

Works just fine. No other setting changed or anything.

tried this:
Quote:Try this, in system/database/drivers/mysql/mysql_driver.php:
Replace this (lines 59-67):
Code:
function db_connect()
    {
        if ($this->port != '')
        {
            $this->hostname .= ':'.$this->port;
        }
        
        return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
    }
with this:
Code:
function db_connect()
    {
        if ($this->port != '')
        {
            $this->hostname .= ':'.$this->port;
        }
        
        $success = @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
                if(!$success) {
                        die('Could not connect: ' . mysql_error());
                }

    }
#2

[eluser]Chad Fulton[/eluser]
Quote:Try this, in system/database/drivers/mysql/mysql_driver.php:
Replace this (lines 59-67):

function db_connect()
{
if ($this->port != '')
{
$this->hostname .= ':'.$this->port;
}

return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
}
with this:

function db_connect()
{
if ($this->port != '')
{
$this->hostname .= ':'.$this->port;
}

$success = @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
if(!$success) {
die('Could not connect: ' . mysql_error());
}

}

That was my advice, and, whoops, I messed up. Since you have persistent connections enabled, you'll have to do the following:

Try this, in system/database/drivers/mysql/mysql_driver.php:
Replace this (lines 77-85):

Code:
function db_pconnect()
    {
        if ($this->port != '')
        {
            $this->hostname .= ':'.$this->port;
        }

        return @mysql_pconnect($this->hostname, $this->username, $this->password);
    }
with this:

Code:
function db_pconnect()
    {
        if ($this->port != '')
        {
            $this->hostname .= ':'.$this->port;
        }

                $success = @mysql_pconnect($this->hostname, $this->username, $this->password);
                if(!$success) {
                        die('Could not connect: ' . mysql_error());
                }
                return $success;
    }
#3

[eluser]pat242[/eluser]
tried that it it now just reads:

Could not connect:
#4

[eluser]Chad Fulton[/eluser]
To my knowledge, the only error that results without giving an error message is an "access denied" error.

You need to make sure that your user has access to that database.
#5

[eluser]pat242[/eluser]
Thanks for your help, I've spent too many evening trying to get it to work. Off to try a different framework.
#6

[eluser]Chad Fulton[/eluser]
Just FYI, this is not a framework issue. You will continue to have this problem regardless of the framework you use. You need to set the permissions appropriately in MySQL so that your user (bari_user) has access to the database (bari_db).

Particularly if you set up MySQL yourself, it is reasonable to assume you may have created the Database/Schema, and then created the User, and forgotten to assign the appropriate privileges to that user.

Although CodeIgniter does have (many) flaws, it is a solid, lightweight framework, and I wouldn't want you to run away with the idea that it is causing the problem here.
#7

[eluser]pat242[/eluser]
Problem Resolved:

system/database/drivers/mysql/mysql_driver.php go to line 84 and change:

mysql_pconnect

to this:

mysql_connect




Theme © iAndrew 2016 - Forum software by © MyBB