does anyone know if there's a script out there that will create a mysql database automatically instead of having to go into cpanel and create a database, username and password manually?
thanks
解决方案
You cannot create a username and password unless you log in yourself with a user with a higher level. That's usually the root. Creating database is a breeze after using the username and password with sufficient privileges.
$dsn = $dsn = "mysql:host=localhost";
$pdo = new PDO($dsn,"root","");
//Creation of user "user_name"
$pdo->query("CREATE USER 'user_name'@'%' IDENTIFIED BY 'pass_word';");
//Creation of database "new_db"
$pdo->query("CREATE DATABASE `new_db`;");
//Adding all privileges on our newly created database
$pdo->query("GRANT ALL PRIVILEGES on `new_db`.* TO 'user_name'@'%';");
?>
In this script, I assumed your root user is called "root" and its password is empty if that's not the case, change line 4 to match.