Reputation: 199
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 ?
Upvotes: 3
Views: 28379
Reputation: 199
Yeah, I have solved this problem changing:
$db['default'] = array('dsn' => '','hostname' => 'telihatyhighschool.edu.bd',
to:
$db['default'] = array('dsn' => '','hostname' => 'localhost',
Upvotes: 0
Reputation: 1560
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',
Upvotes: 0
Reputation: 1123
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
);
Upvotes: 0
Reputation: 1
SOLVED
public_html/application/config/database.php
Upvotes: 0
Reputation: 11
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',
);
Upvotes: 0
Reputation: 375
I had the same error but all the error are resolved by adding privileges to that user
Upvotes: 0
Reputation: 909
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:
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*';
Upvotes: 4
Reputation: 38609
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
);
Upvotes: 0