Welcome Guest, Not a member yet? Register   Sign In
CI can't connect to mySQL database, but a simple mysql_connect works.
#1

[eluser]stevenL[/eluser]
I just uploaded CI to a server and it is refusing to connect. I have changed the database.php settings.

The weird thing is, I can connect directly via PHP if I use this:

Code:
<?php
     $link = mysql_connect('localhost', 'user', 'user_password');
     if (!$link) {
         die('Could not connect: ' . mysql_error());
     }
     echo 'Connected successfully';
     mysql_close($link);
?>

My database settings are set up exactly the same (obviously user, user_password, db_name shown here are not the actual text):

Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "user";
$db['default']['password'] = "user_password";
$db['default']['database'] = "db_name";
$db['default']['dbdriver'] = "mysql";

Am I making some noob error? Do I need to change a setting somewhere else in CI? How can I troubleshoot further?
#2

[eluser]jedd[/eluser]
[quote author="stevenL" date="1238044292"] ... and it is refusing to connect. [/quote]

Elucidate further on that statement with, say, an error message.

Have you loaded the database library?
#3

[eluser]stevenL[/eluser]
CI Error:

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

[eluser]stevenL[/eluser]
Yes the database class is autoloaded. Everything works locally.
#5

[eluser]jedd[/eluser]
To rule out it's not a perms problem [/i]to the database[/i] (not just the server), try doing a mysql_list_tables against your actual DB in your native mysql test code there.

I'd look at cranking up the logging in CI and MySQL as the next step.
#6

[eluser]stevenL[/eluser]
Thanks, jedd.

mysql_list_tables returns the tables.
#7

[eluser]stevenL[/eluser]
And I can't seem to enable logging.
I have set

Code:
$config['log_threshold'] = 4;

And I made the logs folder writable. Is there something else I need to do?
I am beginning to think this CI is incompatible in some way with this host.
#8

[eluser]stevenL[/eluser]
So I reinstalled CI on the server...and it worked. Weird.




Theme © iAndrew 2016 - Forum software by © MyBB