CodeIgniter Unable to connect to your database server using the provided settings Error Message

0 votes

 I have been using CI just fine using the MySQL driver. I want to use the MySQL driver instead, but as soon as I change it, I get the following error message

A Database Error Occurred

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

Filename: core/Loader.php

Line Number: 232

my setting look like this:

$db['default']['hostname'] = $hostname; 
$db['default']['username'] = $username; 
$db['default']['password'] = $password; $db['default']['database'] = $database; 
$db['default']['dbdriver'] = 'mysqli'; 
$db['default']['port'] = "3306"; 
$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; 

where 

$hostname = 'localhost'; 
$username = 'myusernamegoeshere'; 
$password = 'mypasswordgoeshere'; 
$database = 'mydatabasenamegoeshere';

I'm Using:

CI 2.0.2 php 5.3.4 Apache/2.2.17 (Unix) mysql 5.5.13 mysql.default_port 3306



Am I doing anything wrong? If so, please let me know?

Thank you.

Feb 16 in Others by Aditya
• 7,660 points
4,715 views

1 answer to this question.

0 votes

 I'm assuming there is something wrong with PHP configuration.

First, debug your database connection using this script at the end of ./config/database.php :

 

... 
    ... 
    ... 
  echo '<pre>'; 
  print_r($db['default']); 
    echo '</pre>'; 

  echo 'Connecting 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__ . ' Line: ' .__LINE__);

Then see what the problem is.

answered Feb 16 by Soham
• 9,670 points

Related Questions In Others

0 votes
1 answer

HTTP Error 403.14 - Forbidden - The Web server is configured to not list the contents of this directory

Try keeping this into your web config ...READ MORE

answered Feb 11 in Others by Rahul
• 9,680 points
3,961 views
0 votes
1 answer

Using unserialize in PHP throws the same error repeatedly

I googled 'Node no longer exists', and ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,240 points
871 views
0 votes
0 answers

unable to connect to internet in edureka VM

i am unable to connect to internet ...READ MORE

Jun 7, 2019 in Others by Ashok
• 120 points
288 views
0 votes
1 answer

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in.

The issue is that the query given to mysqli_query() is ...READ MORE

answered May 1 in Other DevOps Questions by narikkadan
• 37,660 points
263 views
0 votes
0 answers
0 votes
0 answers

How to retrieve data from multiple tables using a PHP form?

I want to retrieve data from multiple ...READ MORE

Jun 25 in PHP by narikkadan
• 37,660 points
567 views
0 votes
0 answers

Get last executed query in MySQL with PHP/CodeIgniter

In my_model.php, I have: $query1 = ( ...something... ); $query2 ...READ MORE

Jul 22 in PHP by Kithuzzz
• 20,660 points
173 views
0 votes
1 answer

The uploaded file exceeds the upload_max_filesize directive in php.ini error while uploading plugin

After looking at your ERROR, it seems ...READ MORE

answered Feb 8 in Others by Soham
• 9,670 points
128 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP