Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter error when trying to connect to database using mysqli

I am getting Following error in my CodeIgniter application which is live on server.

Here is the output of the error:

A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect(): (HY000/1044): Access denied for user 'xxx'@'localhost' to database 'xxx'

Filename: mysqli/mysqli_driver.php

Line Number: 161

Backtrace:

File: /home/arya123/public_html/application/controllers/Home.php Line: 7 Function: __construct

File: /home/arya123/public_html/index.php Line: 292 Function: require_once

like image 794
Code Craving Avatar asked Oct 31 '25 19:10

Code Craving


2 Answers

you have to set mysql port number which is by default 3306 check this in database.php

use either

'dbport' => '3306',

or

 'hostname' => 'mysql.hostingprovider.com:3306',   
like image 96
Anurag Biradar Avatar answered Nov 03 '25 09:11

Anurag Biradar


Connect localhost with port solves the problem for me.

$db['default'] = array(
    'dsn' => '',
    'hostname' => 'localhost:3308', //Added port here
    'username' => 'root',
    'password' => '1234',
    'database' => 'my_database',
    '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
);
like image 34
Naveen Kumar M Avatar answered Nov 03 '25 09:11

Naveen Kumar M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!