Error not raised while executing wrong query

Hi all,

In a previous question (, I created a table with the column "title".
To check what happens when there is an error during the SQL execution I change to "titl" the name of the previous column.

When running the following script, no error is raised and the SQL query really failed.

Why there is no error message?

My script


$sql  = "INSERT INTO `pouxdagoalyne`.`TEACHINGS` (`title`, `location`, `teaching_date`, `description`, `opening_hours`) ";
$sql .= "VALUES (:title, :location, :teaching_date, :description, :opening_hours)";
	$sth = $dbh->prepare($sql);
catch(PDOException $e)

	$sth->execute(array(':title' => $_POST['teaching-title'], ':location' => $_POST['teaching-location'], ':teaching_date' => $_POST['teaching-when'], ':description' => $_POST['teaching-description'], ':opening_hours' => $_POST['teaching-opening-hours']));   
catch(PDOException $e)
<!DOCTYPE html>
<html lang="fr">
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>Teaching lesson creation</title>
<link rel="stylesheet" href="">
<script src=""></script>
<h1>Create a session: <?php echo $_POST['teaching-title']; ?></h1>
<p>The session <em><?php echo $_POST['teaching-title'] ; ?></em> has been created.</p>

Open in new window

Richard Coffree-commerce Product ManagerAsked:
Who is Participating?
AlexanderREnterprise Web DeveloperCommented:
Ok, that at least rules out syntax error.

Next step is to configure PDO to run in proper mode.

$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

Add those two as soon as possible after the connection.  First options makes pdo use exceptions, as opposed to being silent or output error codes in its return. Second attribute may have to be switched between true and false depending on your driver. If drivers supports actual prepared statements then bad column name will be detected during preparation stage, as opposed to at the end in execution. If driver does not support prepares and get errors from second attribute make it "true".
AlexanderREnterprise Web DeveloperCommented:

should be

Richard Coffree-commerce Product ManagerAuthor Commented:
@AlexanderR, it has changed nothing :-(
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.