CodeIgniter Forums
Testing Database connection - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Testing Database connection (/showthread.php?tid=22862)



Testing Database connection - El Forum - 09-22-2009

[eluser]mrwilson1[/eluser]
I am getting errors that indicate to me that my database is not connecting

<code>Fatal error: Call to a member function select() on a non-object in /home/shivabe1/public_html/ci/system/application/models/twitter_model.php on line 46</code>
Line 46 is simply
<code>$this->db->select('last_message');</code>

I know how to check database connection with regular php, but how do you do it with CI? and where?

Do my settings look correctly filled in as far as the first 5? I was getting an error that the database could not connect with the settings given, but all of a sudden that stopped and now I get the above. I did try an if statement in the model if($db) but that didnt do anything

most names changed to protect the innocent

$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "twit";
$db['default']['password'] = "password";
$db['default']['database'] = "shivabe1_twitter";
$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";

Thanks


Testing Database connection - El Forum - 09-22-2009

[eluser]wabu[/eluser]
Are you autoloading the database library? If so I'd think you'd see an error before then.

If not, you might need to add a port setting:

Code:
$db['default']['port'] = "3306";



Testing Database connection - El Forum - 09-22-2009

[eluser]mrwilson1[/eluser]
Yes, I had taken auto load out and forgot about it. I put it back in and added the port but still cannot connect. I know the password and name i am using are correct

I do now get the early warning cannot connect with provided settings

Is the database setting ($db[‘default’][‘database’] = “shivabe1_twitter”;( correctly formatted like it would be in a normal connection?

Incidentally I have 2 databases and cant connect to either one


Testing Database connection - El Forum - 09-22-2009

[eluser]wabu[/eluser]
Have you already checked the connection settings using regular PHP? If not it might help pinpoint the problem.


Testing Database connection - El Forum - 09-22-2009

[eluser]mrwilson1[/eluser]
Good idea. I will run up some quick stuff and see what happens. thanks for the help Smile


Testing Database connection - El Forum - 09-22-2009

[eluser]mrwilson1[/eluser]
Got this solved, it seems like I had to add "shivebe1 to

original
$db[‘default’][‘username’] = “twit”;

New
$db[‘default’][‘username’] = “shivabe1_twit”;

which is strange because I have 2 other domains with this host and thats not required.

Many thanks to WABU