FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » try / catch or INSERT INTO... ON DUPLICATE KEY UPDATE
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: try / catch or INSERT INTO... ON DUPLICATE KEY UPDATE [message #175296 is a reply to message #175295] Thu, 01 September 2011 05:35 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
Member
On Sep 1, 12:37 am, Chuck Anderson <cycletour...@invalid.invalid>
wrote:
> jwcarlton wrote:
>> I promise that this is a PHP question, and not MySQL!
>
>> I'm currently sending a query of INSERT INTO... ON DUPLICATE KEY
>> UPDATE. But, I'd like to know which one happened in my PHP; was it
>> new, or was it updated?
>
>> Is there a way to find this? Or should I do something like:
>
>> try {
>>   $query = sprintf("INSERT...");
>>   $sth = mysql_query($query) or die(mysql_error());
>
>>   $duplicate = false;
>> }
>
>> catch (Exception $e) {
>>   $query = sprintf("UPDATE...");
>>   $sth = mysql_query($query) or die(mysql_error());
>
>>   $duplicate = true;
>> }
>
> Your promise is an empty one. It's very much MySQL, but I'll give it to
> ya anyway: :-)
>
> http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
>
> .... right there in the first several lines ...
>
> "With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if
> the row is inserted as a new row and 2 if an existing row is updated."
>
> Php -> mysql_affected_rows($link)
>
> --
> *****************************
>  Chuck Anderson • Boulder, CO
> http://cycletourist.com
>  Turn Off, Tune Out, Drop In
> *****************************

Touche! Thanks, Chuck. It's obvious once you know what to look for :-)
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: does paypal standard method supports for recurring payment.
Next Topic: php help
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 29 22:49:33 GMT 2024

Total time taken to generate the page: 0.05543 seconds