0

I have SQL code that executes CREATE TABLE and DROP TABLE in the same query. When I run it, it prints bool(false) meaning error. Can it be done in one query?

$dbh = new PDO("sqlite::memory:");
$stmt = $dbh->prepare("create table a ( i int, j int);drop table a");
var_dump($stmt);

I don't know why but it works if I try it again.

jiwopene
  • 3,077
  • 17
  • 30

1 Answers1

0

You need to execute your query Like this : $stmt ->execute();

And yes you can create and delete a table in the same query.

You can maybe try this to catch an error, it will help you try { $db = new PDO('sqlite::memory'); echo "SQLite created in memory."; } catch(PDOException $e) { echo $e->getMessage(); }

Velen
  • 1
  • 2