I’m just trying to do a simple insert:
$dbh = new PDO("mysql:host=" . WEBSITE_SERVER . "; dbname=fluenz_website", WEBSITE_LOGIN, WEBSITE_PW);
$query = $dbh->prepare("INSERT INTO crm_orders (crm_id, order_num, channel) VALUES (:crm_id, :order_num, :channel)");
if($query->execute(array(':crm_id'=>$crm_id, ':order_num'=>$order_num, ':channel'=>$channel))){
echo 'PDO SUCCESS';
}else{
echo 'PDO FAILURE';
}
But it’s failing. Can someone tell me why? And even better, is it possible to get a more helpful return value from the execute() method than simply true or false?
Hard to say. Should those values be quoted? The error thrown by MySQL would be useful to diagnose the problem. Which leads me to…
So long as PDO is set up to throw exceptions on errors…
…wrap it in a
try/catchblock and examine the exception thrown.