In my web application, it has a self installing functionality so, after it is copied to the server, you just need to run the install.php file which has the following PHP code.
define("DB_SERVER","localhost");
define("DB_USER","db_user");
define("DB_PASS","pass");
//create mysql connection
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS);
if(mysqli_connect_errno()){
die("Connection Error");
}else{
echo "MySQL Connection Successful!";
}
//create database if not exists
$sql = "CREATE DATABASE equiz";
$mysqlQuery = mysqli_query($connection, $sql);
if($mysqlQuery){
echo "Database Created Successfully";
}else{
die("Database Not Created!");
}
In the localhost, this works perfectly fine. But, when this is moved to the server, it gives me this error
Access denied for user 'db_user'@'localhost' to database 'equiz'
I had created the user db_user in advance along with another database and I'm sure he was granted with all the permissions. But I'm not sure if those permissions were for that particular database only.
Anyway any clue for this error ? I know little bit PHP but very new to real world web servers.