CodeIgniter Forums
when I load database library, im getting error.... - 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: when I load database library, im getting error.... (/showthread.php?tid=38327)

Pages: 1 2 3


when I load database library, im getting error.... - El Forum - 02-04-2011

[eluser]reka[/eluser]
when I load database library, im getting error.... I really dont know how to solve this problem :down: :down: :down:

here is my error message.. :


Code:
A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 242



when I load database library, im getting error.... - El Forum - 02-04-2011

[eluser]Eric Barnes[/eluser]
That means your connection info is wrong in config/database.php

You should double or triple check those settings.


when I load database library, im getting error.... - El Forum - 02-04-2011

[eluser]reka[/eluser]
no..im pretty sure that my connection settings are correct... :roll:
it just happend in my web hosting..

I dont have problems like this before in getcloudigniter.com free web hosting


when I load database library, im getting error.... - El Forum - 02-05-2011

[eluser]cideveloper[/eluser]
who is your new host?

some hosting companies put prefixes in front of database names. Can you show your database config file? blank out the username and password fields.


when I load database library, im getting error.... - El Forum - 02-05-2011

[eluser]reka[/eluser]
here is my database config file :

Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


im using default settings from codeigniter...
this problem really make me confused....


when I load database library, im getting error.... - El Forum - 02-05-2011

[eluser]InsiteFX[/eluser]
You can not use the default setting!

You need to fill in the others...

Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'your username';
$db['default']['password'] = 'your password';
$db['default']['database'] = 'your database name';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

If you do not have a databse then you will need to create one.

InsiteFX


when I load database library, im getting error.... - El Forum - 02-07-2011

[eluser]reka[/eluser]
no, I was setting it correctly, and I've made a user and database...
but I still getting error like that.... 8-/
I think the problem is in my webhosting..
but I don't know correctly..


when I load database library, im getting error.... - El Forum - 02-07-2011

[eluser]InsiteFX[/eluser]
Email your hosting support and ask them what your settings should be.

InsiteFX


when I load database library, im getting error.... - El Forum - 02-08-2011

[eluser]John_Betong[/eluser]
 
 
For debugging Database connection problems I use this script at the end of my ./config/database.php
Code:
...
  ...
  ...
  echo '<pre>';
     print_r($db['default']);
  echo '</pre>';

  echo 'Trying to connect to database: ' .$db['default']['database'];
  $dbh=mysql_connect
  (
    $db['default']['hostname'],
    $db['default']['username'],
    $db['default']['password'])
    or die('Cannot connect to the database because: ' . mysql_error());
    mysql_select_db ($db['default']['database']);

    echo '<br />   Connected OK:'  ;
    die( 'file: ' .__FILE__ . '--&gt; Line: ' .__LINE__);
&nbsp;
&nbsp;
&nbsp;


when I load database library, im getting error.... - El Forum - 02-09-2011

[eluser]Unknown[/eluser]
[quote author="John_Betong" date="1297247767"]&nbsp;
&nbsp;
For debugging Database connection problems I use this script at the end of my ./config/database.php
Code:
...
  ...
  ...
  echo '<pre>';
     print_r($db['default']);
  echo '</pre>';

  echo 'Trying to connect to database: ' .$db['default']['database'];
  $dbh=mysql_connect
  (
    $db['default']['hostname'],
    $db['default']['username'],
    $db['default']['password'])
    or die('Cannot connect to the database because: ' . mysql_error());
    mysql_select_db ($db['default']['database']);

    echo '<br />   Connected OK:'  ;
    die( 'file: ' .__FILE__ . '--&gt; Line: ' .__LINE__);
&nbsp;
&nbsp;
&nbsp;[/quote]

BRILLIANT! I had the same problem connecting to my db - and it was not my first try with CI... But this one, I simply couldnt figure out why it couldnt connect.

With your debugscript, I noticed that I had mixed up the database name and password, and your script told me that it tried to connect to Database: mypassword.

Really good debug script, thank you very much Smile