Avatar of Robert Granlund
Robert Granlund
Flag for United States of America asked on

PHP PDO

Would somebody give me a good example of an insert statement  using PDO?
PHP

Avatar of undefined
Last Comment
Robert Granlund

8/22/2022 - Mon
Olaf Doschke

Would this help?
http://www.mustbebuilt.co.uk/php/insert-update-and-delete-with-pdo/

Or what other aspect of PDO is uncelar to you?
You don't have to use prepared statements, but it's a big advantage to do that.

Bye, Olaf.
Robert Granlund

ASKER
Isn't there a "try" statement?
Dave Baldwin

Doesn't make any sense to me but here is the page on PDO Exceptions:  http://php.net/manual/en/class.pdoexception.php
Your help has saved me hundreds of hours of internet surfing.
fblack61
Olaf Doschke

Well, try/catch only is necessary, if you run PDO in the PDO::ERRMODE_EXCEPTION mode. Default should be PDO::ERRMODE_SILENT: Just set error codes, so you only check, whether the PDOStatement::execute() returns FALSE and in that case check out PDO::errorCode and PDO::errorInfo.

If you have an error in your query, that'll happen in MySQL or whatever backend. It's your concern, certainly, but the stability of PHP is not in any danger, you just don't have a query result and should handle that. So since the error is happening in another process most likely even on a remote database server, it's not necessary to let that cause an exception in PHP.

It's a bit of taste, if your general error handling is based on exceptions, it's a simple setting and if you don't catch the exception at this level, it'll bubble up to the next higher level.

Bye, Olaf.
SOLUTION
Scott Fell

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Robert Granlund

ASKER
Thanks Ray.  I read that page a while back and at the time most of it went over my head.  This time around it really cleared a few this up.  Thanks.