<?php
function CreateDatabase($username, $database)
{
global $con;
if($con) {
$createdatabase = $con -> prepare("
CREATE DATABASE ?");
$createdatabase -> execute(array($database));
$createdatabase = $con -> prepare("
GRANT ALL
ON
?.*
TO
?@'localhost'");
$createdatabase -> execute(array($database, $username));
$createdatabase = $con -> prepare("
FLUSH PRIVILEGES");
$createdatabase -> execute();
return true;
}
return false;
}
For some reason this code won't run the way it should. I quadrupled checked that the strings $username and $database are correctly passed on.
Can you see any errors here? Any hints, tips on how to resolve this? Just started learning PDO today, so if I'm doing it wrong or do it in a bad practice, please tell me.
I'm creating a database management system for my clients, where they can create a user if it doesn't already exist, then create a database and look over the info. If anyone is interested in helping out finishing it, I would be most grateful!