views:

54

answers:

2

I can't find any reference to using prepared statements with "ON DUPLICATE KEY UPDATE" with MySQL and PHP. Am I correct in thinking that this is not possible?

-Jim

A: 

You can most certainly use ON DUPLICATE KEY UPDATE with PHP+MySQL. Have you tried it? If you have, what problem did you run into?

Amber
Sorry, my question wasn't clear, so I edited it. I have used ON DUPLICATE KEY UPDATE many times, but never with a prepared statement. I looked several places for instructions on how this might be done but found nothing. Before I waste an afternoon on futile experimentation I thought I would check to see if anyone can confirm that this is actually feasible.-Jim
Jim H.
A: 

You should be able to run every SQL query as a prepared statement. I don't know why you think there would be any exception for ON DUPLICATE KEY UPDATE. Try it first and ask us if there are any problems.

Emil Vikström
Thanks Emil. I will give it a try, although I can't picture how it would work. Would you add the ON DUPLICATE KEY UPDATE to the query in mysqli_prepare and also have the replacement values as ? marks? If that will work then it would be very useful to me. I will report on my results, although it may be a while before I have time to try this.Jim
Jim H.