3

This is a codeigniter project. my given database information is right.It works perfectly in localhost. But after uploading my project in hosting site, it still shows an 'access denied' error.

This is my database:

 $db['default'] = array(
    'dsn' => '',
    'hostname' => 'telihatyhighschool.edu.bd',
    'username' => 'db_username',
    'password' => 'db_password',
    'database' => 'db_name',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array() ,
    'save_queries' => TRUE
);

How can I solve this ?

Mamun Sabuj
  • 189
  • 1
  • 2
  • 6

8 Answers8

4

In cpannel actually username and database name has cpanel username prefix eg

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

$db['default']['hostname'] = 'localhost'; //literaly put localhost
$db['default']['username'] = 'cpanelusername_root';
$db['default']['password'] = 'password';
$db['default']['database'] = 'cpanelusername_db name';
$db['default']['dbdriver'] = 'mysqli'; ///use this extension
$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;

in more simple words

Host = localhost (literally put localhost)
Database name = (cpanelUsername_databaseName)
Database username = (cpanelUsername_databaseUsername)
Database password = (******)

NOTE: When connecting to a database, you need to ensure that:

  1. You've created a database
  2. You've created a database username
  3. You've assigned that user with privileges to your database

Your MySQL connections may use 127.0.0.1 or the IP address of your server, and MySQL will reject the connection if access isn't granted for the specific IP address used.

Verify the permission tables (reloading grants if required) on the server and that you're connecting to

Regrant Preveliges by :

GRANT ALL PRIVILEGES on *.* to 'user'@'IP' IDENTIFIED BY '*UserPass*';
Linus
  • 899
  • 3
  • 19
  • 33
0

If your hosting server is Linux,

Change hostname value to localhost

$db['default'] = array(
    'dsn' => '',
    'hostname' => 'localhost',
    'username' => 'user',
    'password' => 'XXXXXXXX',
    'database' => 'mydbname',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array() ,
    'save_queries' => TRUE
);
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

Yeah, I have solved this problem changing:

$db['default'] = array('dsn' => '','hostname' => 'telihatyhighschool.edu.bd',

to:

$db['default'] = array('dsn' => '','hostname' => 'localhost',
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Mamun Sabuj
  • 189
  • 1
  • 2
  • 6
0

I had the same error but all the error are resolved by adding privileges to that user

noushad mohammed
  • 375
  • 1
  • 4
  • 20
0

Try to use the plain password with no special characters, below is the example:

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'password',
    'password' => 'Mynewpass@756',
    'database' => 'database_name',
);
Shento
  • 1
  • 4
0

I resolved this issue by adding a User under Privileges for the database. This User should have the same values as database.php:

'hostname' => 'localhost',
'username' => 'username',
'password' => 'password',
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Kanak Sony
  • 1,570
  • 1
  • 21
  • 37
0

SOLVED

  1. create a new database from cpanel
  2. create a new username
  3. assigned that user with privileges to your database
  4. modify file database.php with new information database

public_html/application/config/database.php

  1. export database from your old hosting cpanel - option phpmyadmin
  2. import database to you new hosting cpanel- option phpmyadmin
  3. DONE
Robert
  • 1
0

I had same problem. I had codeigniter project live on my server.

Solution:

In File Manager in codeigniter project public_html/your_project_name/application/config/database.php

I added the password which was missing. [ Password of user when you created it in Cpanel -> MySQL Databases ]

**Make sure you have assigned the database access to this user with all privileges and your configurations in database.php are correct.

Mine are:

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'YOUR_DOMAIN_NAME', //Ex- abcd.com
    'username' => 'USER_NAME_HERE',// CREATED IN CPANEL->MySQL Database
    'password' => 'PASSWORD_HERE', // PASSWORD OF ABOVE USER
    'database' => 'YOUR_DB_NAME',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);
Makarand
  • 983
  • 9
  • 27