chapter4/createtable/index.php (excerpt)
DO I put the PHP opening tags and closing if I did that it shows error on line 9 and 10 the $pdo->exec($sql)
try
{
$sql = 'CREATE TABLE joke (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
joketext TEXT,
jokedate DATE NOT NULL
) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB';
$pdo->exec($sql);
}
catch (PDOException $e)
{
$output = 'Error creating joke table: ' . $e->getMessage();
include 'output.html.php';
exit();
}
$output = 'Joke table successfully created.';
include 'output.html.php';
Yes, you do need the opening and closing PHP tags, however, what I am not seeing is where you are declaring your $pdo object. Defining its connection to the database, etc. which is why you are getting an error on the $pdo->exec($sql); command
Ok thanks I got it, but the book did not say I have to include the db connection
What vs of php is used in this book
I can’t say for certain that you would have had to, but based on what you provided me to look at, that was my best guess. I personally do not have a copy of this book so I can’t tell you if what I said was what the author intended.
It sounds like you got it working, so all is good
If you need more help, don’t hesitate to ask.