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 #175295 is a reply to message #175294] Thu, 01 September 2011 04:37 Go to previous messageGo to previous message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma:
Member
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
*****************************
[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:33:53 GMT 2024

Total time taken to generate the page: 0.04401 seconds