I've tried following the PHP.net instructions for doing SELECT
queries but I am not sure the best way to go about doing this.
I would like to use a parameterized SELECT
query, if possible, to return the ID
in a table where the name
field matches the parameter. This should return one ID
because it will be unique.
I would then like to use that ID
for an INSERT
into another table, so I will need to determine if it was successful or not.
I also read that you can prepare the queries for reuse but I wasn't sure how this helps.
Best Answer
You select data like this:
You insert in the same way:
I recommend that you configure PDO to throw exceptions upon error. You would then get a
PDOException
if any of the queries fail - No need to check explicitly. To turn on exceptions, call this just after you've created the$db
object: