As I continue my rocky journey into understanding PDO_SQL queries and how they differ from MySQL queries, I have hit another roadblock.
I am trying to display an error message, if an error is encountered when adding a record. I had working code with MySQL, but now I am getting a different result with PDO. I know that PDO appears to handle errors differently through PDOException??? (I really don’t know what I’m talking about though and reading that dang PHP manual is NOT helpful – it might as well be written in an ancient language – it is not newbie friendly).
Here is the code I have from MySQL which I am trying to use as well for PDO:
$sql_add = “INSERT INTO tableCategories (cats_name, cats_rank) values (’” . $add_newName . “’, '” . $add_newRank . “’);”;
if ($pdo->query($sql_add) !== TRUE) {
echo "Error adding record: " . $pdo->errorInfo();
}
(I used to have $pdo->error; in the above line, but I thought changing it to $pdo->errorInfo(); would be correct based on what I tried to read in the PHP manual.)
While the query and insert is working fine, it is triggering my condition and outputting the following:
Error adding record: Array
I’m guessing I need to test and output the error message differently now? I can’t figure out how to do this though. Can someone please help.