I am trying to create a new user to my mysql database and login with it to create a new database. I tried the following code. But it results some errors.
<?php
$mysqli=new mysqli("localhost","username","password@123") or die(".........");
$mysqli->query("CREATE USER 'new_username'@'localhost' IDENTIFIED BY '123456';");
$mysqli->query("GRANT ALL ON db1.* TO 'new_username'@'localhost'");
$mysqli->close();
$mysqli=new mysqli("localhost","new_username","123456") or die(".........");
if($mysqli->query("Create database if not exists New_DB_Name")){
"Failed creating new database: ".$mysqli->connect_errno();
die();
}
$mysqli->select_db("New_DB_Name");
$mysqli->close(); ?>
and here is the errors
Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'new_username'@'localhost' (using password: YES) in /home/public_html/sign-up/conn.php on line 10
Warning: mysqli::query(): Couldn't fetch mysqli in /home/public_html/sign-up/conn.php on line 12
Warning: mysqli::select_db(): Couldn't fetch mysqli in /home/public_html/sign-up/conn.php on line 19
Warning: mysqli::close(): Couldn't fetch mysqli in /home/public_html/sign-up/conn.php on line 20
Edit: Actually its not creating new user. that's the trouble here.