Q695 Posted June 22, 2014 Share Posted June 22, 2014 What's wrong with the query, I'm not getting errors outputted: // configuration $dbtype = "MySQL"; $dbhost = "localhost"; $dbname = "eagle"; $dbuser = "root"; $dbpass = ""; // database connection $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); // query $sql = "INSERT INTO member_data (fname, mname, lname, street, apt, city, state, zip, email, number, job, awarded) VALUES (:fname, :mname, :lname, :street, :apt, :city, :state, :zip, :email, :number, :job, :awarded) "; echo $sql; $q = $conn->prepare($sql); $q->execute(array(':fname'=>$fname, ':mname'=>$mname, ':lname'=>$lname, ':street'=>$street, ':apt'=>$apt, ':city'=>$city, ':state'=>$state, ':zip'=>$zip, ':email'=>$email, ':number'=>$number, ':job'=>$job, ':awarded'=>$awarded )); How do I run an or die to output the error? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted June 22, 2014 Share Posted June 22, 2014 To get the error message with PDO, either run your prepare query in a try/catch block to catch the exception Or use PDO::errorInfo Also dont use die to output errors. It is ok for development but not when your code goes live. Instead use trigger_error Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 22, 2014 Share Posted June 22, 2014 it's easiest to use exceptions with pdo statements to catch errors and handle logging/displaying error messages. the connection always throws an exception if it fails and once you have created a connection, you can configure the pdo instance to throw exceptions, which you can use a try/catch block around to handle, for all other statements that fail. see this link on how to use a try/catch block for the connection and how to configure pdo statements to throw exceptions - http://us3.php.net/manual/en/pdo.error-handling.php Quote Link to comment Share on other sites More sharing options...
Q695 Posted June 22, 2014 Author Share Posted June 22, 2014 (edited) lol had a pdo quoting error. What does :variable name mean, compared to $variable mean in this pdo tutorial: http://www.phpeveryday.com/articles/PDO-Insert-and-Update-Statement-Use-Prepared-Statement-P552.html Edited June 22, 2014 by Q695 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted June 22, 2014 Share Posted June 22, 2014 You should be looking at the manual on PDO prepared statements for the answer. The manual is always the first place you should look for understanding what a function does. Quote Link to comment Share on other sites More sharing options...
Q695 Posted June 22, 2014 Author Share Posted June 22, 2014 it doesn't explain the different symbols on a cheat sheet. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted June 22, 2014 Share Posted June 22, 2014 The second sentence explains it from the page I linked to. The SQL statement can contain zero or more named (:name) or question mark (?) parameter markers for which real values will be substituted when the statement is executed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.