Error not raised while executing wrong query

Hi all,

In a previous question (http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28646127.html), 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
<?php	

include("data-connection.inc.php");

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

try
{
	$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)
{
    die($e->Message);
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>Teaching lesson creation</title>
<link rel="stylesheet" href="">
<script src=""></script>
</head>
<body>
<h1>Create a session: <?php echo $_POST['teaching-title']; ?></h1>
<p>The session <em><?php echo $_POST['teaching-title'] ; ?></em> has been created.</p>
</body>
</html>

Open in new window

LVL 1
Richard Coffree-commerce Product ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexanderREnterprise Web DeveloperCommented:
die($e->Message);

should be

die($e->getMessage());
0
Richard Coffree-commerce Product ManagerAuthor Commented:
@AlexanderR, it has changed nothing :-(
0
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_ERRMODE, PDO::ERRMODE_EXCEPTION);
$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".
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.