我正在开发一个不适合多租户的应用程序。所以我的计划是为每个客户帐户创建不同的 MySQL 数据库和用户。我遇到了问题,如果您能看到我的代码有什么问题,那就太好了 - 我没有收到任何错误,但没有添加数据库/用户。
$dsn = "mysql:host=localhost";
$pdo = new PDO($dsn,"REMOVED","REMOVED"); // I removed the login.
$username = 'testing';
$password = 'password';
$dbname = 'test_table';
//Creation of user
$STH = $pdo->prepare("CREATE USER `:username` @'%' IDENTIFIED BY `:password`;");
$STH->execute(array(':username' => $username, ':password' => $password));
//Creation of database "new_db"
$STH = $pdo->prepare("CREATE DATABASE `:dbname`;");
$STH->execute(array(':dbname' => $dbname));
//Adding all privileges on our newly created database
$STH = $pdo->prepare("GRANT ALL PRIVILEGES on `:dbname`.* TO `:username`@'%';");
$STH->execute(array(':dbname' => $dbname,':username' => $username));