Welcome Guest, Not a member yet? Register   Sign In
Having trouble connecting to mysql database
#1

Hello,

I want to connect MySQL community server, but I keep getting this error message over and over:8

CodeIgniter\Database\Exceptions\DatabaseException #8

Unable to connect to the database.


This is the code:

$custom = [
    'DSN'      => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => 'root',
    'database' => 'world',
    'DBDriver' => 'MySQLi',
    'DBPrefix' => '',
    'pConnect' => false,
    'DBDebug'  => (ENVIRONMENT !== 'production'),
    'cacheOn'  => false,
    'cacheDir' => '',
    'charset'  => 'utf8',
    'DBCollat' => 'utf8_general_ci',
    'swapPre'  => '',
    'encrypt'  => false,
    'compress' => false,
    'strictOn' => false,
    'failover' => [],
    'port'    => 3306,
];

$db = \Config\Database::connect($custom);
$db->query("SELECT * FROM city");
$db->close();


Any kind of help would be appreciated
Reply
#2

And where are you calling the bottom database code?

Database code should be called from a model.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB