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
Switch to threaded view of this topic Create a new topic Submit Reply
try / catch or INSERT INTO... ON DUPLICATE KEY UPDATE [message #175294] Thu, 01 September 2011 03:50 Go to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
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;
}
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 next message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma: 0
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
*****************************
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: 0
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 :-)
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Sun Nov 10 16:10:43 GMT 2024

Total time taken to generate the page: 0.03094 seconds