0

This seems so stupid.

This works:

$db = "nameone";
$coll = "utf8_bin";
$sth = $this->dbh->prepare("CREATE DATABASE $db COLLATE $coll");
$sth->execute();

But this gives the following errors: $sth->errorInfo[0] => 42000. $sth->errorInfo[2] => You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''nametwo' COLLATE 'utf8_bin'' at line 1.

$db = "nametwo";
$coll = "utf8_bin";
$sth = $this->dbh->prepare('CREATE DATABASE :db COLLATE :coll'); // Changing to double quotes does not matter. Get same error.
$sth->bindParam(':db', $db);
$sth->bindParam(':coll', $coll);
$sth->execute();

What am I missing that would cause the second code with the named parameters and bindParam to error like that. Please note that I'm using database name and collation type, not table name and column name, and that the errors are syntax related. Is there a module that needs to be enabled in php.ini?

Thanks,

Steve

  • 1
    A: You can't bind tables/columns. Consult the duplicate. – Funk Forty Niner May 08 '17 at 20:05
  • *"Is there a module that needs to be enabled in php.ini?"* - A: no. – Funk Forty Niner May 08 '17 at 20:07
  • Thanks for the reply. Please note that I'm using a database name and a collation type, not a table name or a column name. So, are you saying that the title of the previous answer should be expanded to include that table names, column names, database names and collation types cannot be used as parameters? Regards. Steve. – steve_qwerty May 08 '17 at 20:24

0 Answers0