-1

I am new to PhP , and i am kind of stuck with this problem : i have a database created end when i try to use PDO exec() to create a table nothing happends , no table is created, no error message is displayed .I tryed validating my code online and got no error.Please help.Thanks.

$host = 'localhost';
$db = 'test';
$user = 'root';
$pass = '';

try{
$connect = new PDO("mysql:host = $host ; dbname = $db", $user , $pass);
$sql = "CREATE TABLE IF NOT EXISTS book(
id INT(20) NOT NULL UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(20) NOT NULL,
autor VARCHAR(20) NOT NULL
)";
$connect->exec($sql);
$connect = null;
}catch(PDOException $e){
$e->getMessage();
}
  • possible duplicate of [PDO query fails but I can't see any errors. How to get an error message from PDO?](http://stackoverflow.com/a/15990858/476) – deceze Dec 19 '13 at 09:49
  • Your problem has nothing to do with PDO and exec. You need to learn proper SQL prior running it via PHP. – Your Common Sense Dec 19 '13 at 09:51
  • No doubt i need to learn a lot , so maybe you could inlight me with some of yours vaste knoledge ... – user2227542 Dec 20 '13 at 17:38
  • I have the same problem and my SQL statement is absolutely correct. If you have a solution to this problem, please post it. It will help others with same issues – Pallavi Prasad Jul 13 '17 at 05:17

1 Answers1

0

In your catch block, you're not actually doing anything with the exception message. Try changing

$e->getMessage();

to

echo $e->getMessage();

and see if that shows you any errors.

JustAnotherCoder
  • 368
  • 1
  • 2
  • 10