my problem is that I'm trying to create a DB from php, with queries prepared, but mysql gives me an error.
The PHP code is:
private static $sql = array(
'create database :nombreBD default character set utf8 collate utf8_unicode_ci;',
'create user :usuario identified by :clave;',
'grant all on :nombreBD.* to :usuario;',
'flush privileges;',
'use :nombreBD;'
);
static function createScheme(MySql $mysql, $database, $user, $password) {
$arrayParametros = array(
0 => array('nombreBD' => htmlentities($database, ENT_NOQUOTES, 'UTF-8')),
1 => array('usuario' => $user,
'clave' => $password),
2 => array('nombreBD' => htmlentities($database, ENT_NOQUOTES, 'UTF-8'),
'usuario' => $user),
4 => array('nombreBD' => htmlentities($database, ENT_NOQUOTES, 'UTF-8'))
);
foreach (self::$sql as $indice => $sentencia) {
$parametros = array();
if(isset($arrayParametros[$indice])) {
$parametros = $arrayParametros[$indice];
}
$mysql->execute($sentencia, $parametros);
}
}
But at the time it gives me the following errors:
create database: DB name default character set utf8 collate utf8_unicode_ci;
array (
'nameBD' = > 'Base Data',
)
array (
0 = > '42000',
1 = > 1064,
2 = > 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \ '\' Albayda \ 'default character set utf8 collate utf8_unicode_ci \' at line 1 ',
)
The problem is that when in phpMyAdmin I enter the command by mysql, if we put quotes it gives error.
How can I do it?