what is better practice for setting your connection to the database. using normal arrays or associative array? and when i use associative array i have this error Warning: mysqli::__construct(): (HY000/1044): Access denied for user ''@'localhost' to database 'cms' in C:\xampp\htdocs\cms\includes\db.php on line 21, but it says that im connected. We are connected!
<?php
//stores the database host,user,pass,name into array
/*$db['db_host'] = "localhost";
$db['db_user'] = "root";
$db['db_pass'] = "";
$db['db_name'] = "cms";*/
/*$db = array("db_host"=>"localhost",
"db_user"=>"user",
"db_pass"=>"",
"db_name"=>"cms");*/
//we loop through each of the array
foreach ($db as $key => $value){
define(strtoupper($key), $value);
}
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(isset($connection)){
echo "We are connected!";
}else{
echo "Connection failure!";
}