Why can not execute the command

$STH = $DBH->prepare("CREATE TABLE table1(ID int not null auto_increment primary key)"); $STH->execute(); 

A function

 $DBH->exec("CREATE TABLE table1(ID int not null auto_increment primary key)"); 

performed without any problems.

Can you explain why?)

PS $ DBH = new PDO ("mysql: host = $ host; dbname = $ db_name", $ user, $ pass);

  • Surely you get an error returned (with an explanation) after calling $DBH->prepare("CREATE ... - E_p
  • What means it is impossible? Do you have some kind of error or what? - Firepro
  • No error is displayed. The question is this. Just a blank sheet (or if there is an echo displays it) - Samvel
  • Tried to write in try {} catch (PDOException $e) ... without it. - Samvel
  • Error suppression turned off? - br3t

1 answer 1

MySQL documentation

SQL Syntax Allowed in Prepared Statements

Here or the driver does not support (security). Or you need to pass at least one variable.