PHP Learner
PHP Learner

Reputation: 111

Unable to connect to your database server using the provided settings in Codeigniter

Actually I'm trying to configure my codeigniter live file to localhost.

I have,

  1. created a database called test_bs
  2. then imported the tables
  3. Then change the base_url like $config['base_url']=http://localhost/gu_ci/'; and $config['index_page']='index.php'; in config.php
  4. And then did a change on database.php,Which contains

    $active_group = 'default';
    $active_record = TRUE;
    
    $db['default']['hostname'] = 'localhost';
    $db['default']['username'] = 'root';
    $db['default']['password'] = ' ';
    $db['default']['database'] = 'test_bs';
    $db['default']['dbdriver'] = 'mysql';
    $db['default']['dbprefix'] = '';
    $db['default']['pconnect'] = TRUE;
    $db['default']['db_debug'] = TRUE;
    $db['default']['cache_on'] = TRUE;
    $db['default']['cachedir'] = 'application/cache/';
    $db['default']['char_set'] = 'utf8';
    $db['default']['dbcollat'] = 'utf8_general_ci';
    $db['default']['swap_pre'] = '';
    $db['default']['autoinit'] = TRUE;
    $db['default']['stricton'] = FALSE;
    

My .htacess file having:

  RewriteEngine On
  RewriteBase /new_admin/

  RewriteCond %{REQUEST_URI} PIE.htc
  AddType text/x-component .htc
  RewriteRule (.*) static/PIE.htc [L]

  RewriteCond %{REQUEST_URI} !^/new_admin/static/

  RewriteRule (.*)$ index.php [L]

I'm getting the following error:

     A Database Error Occurred

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

     Filename: C:\xampp\htdocs\gunify_ci\system\database\DB_driver.php

     Line Number: 124

I have referred Refer1, Refer2,Refer3,Refer4,Refer5 and so on... The last link just display the welcome message like: enter image description here But none of the solution helped me!!

Guide me to solve this!!

Upvotes: 1

Views: 32556

Answers (1)

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

$db['default']['password'] = ''; there is an space, remove it

use below settings

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

Edit 01

Use this .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

Edit 02

your folder structurer should be

  1. Application
  2. assets
    • css
      1. boostrap.css
      2. style.css
    • js
    • images
  3. system
  4. .htacess
  5. index.php

so code will be:

<link href="<?php echo base_url(); ?>assets/css/bootstrap.css" rel="stylesheet" />

Upvotes: 4

Related Questions