diff --git a/db/Provision/Service/db/mysql.php b/db/Provision/Service/db/mysql.php index 5f1a7cbf..8e0e61f3 100644 --- a/db/Provision/Service/db/mysql.php +++ b/db/Provision/Service/db/mysql.php @@ -55,13 +55,20 @@ class Provision_Service_db_mysql extends Provision_Service_db_pdo { } function grant($name, $username, $password, $host = '') { + $this->create_user($username, $password); $host = ($host) ? $host : '%'; + $statement = "GRANT ALL PRIVILEGES ON `%s`.* TO `%s`@`%s` IDENTIFIED BY '%s'"; if ($host != "127.0.0.1") { $extra_host = "127.0.0.1"; - $success_extra_host = $this->query("GRANT ALL PRIVILEGES ON `%s`.* TO `%s`@`%s` IDENTIFIED BY '%s'", $name, $username, $extra_host, $password); + $this->query($statement, $name, $username, $extra_host, $password); } // Issue: https://github.com/omega8cc/provision/issues/2 - return $this->query("GRANT ALL PRIVILEGES ON `%s`.* TO `%s`@`%s` IDENTIFIED BY '%s'", $name, $username, $host, $password); + return $this->query($statement, $name, $username, $host, $password); + } + + function create_user($username, $password) { + $statement = "CREATE USER IF NOT EXISTS `%s` IDENTIFIED BY '%s'"; + return $this->query($statement, $username, $password); } function revoke($name, $username, $host = '') {