Connecting Tech Pros Worldwide Help | Site Map

Not getting expected MySQL error

  #1  
Old July 17th, 2005, 02:35 AM
KIPAX
Guest
 
Posts: n/a


I am inserting values into a row.. works OK

If I try to insert a value into a row that doesnt exist (using where)
it always returns true the same as if it did work

I want to update rows that have one unique field.. if the row doesnt
exists it should return 0 rows updated.. I then create the row...

But it always returns 1 even when I update a row that doesnt exist..
How do I get an error or a false return?

Any help appreciated :)


  #2  
Old July 17th, 2005, 02:35 AM
Jon Kraft
Guest
 
Posts: n/a

re: Not getting expected MySQL error


KIPAX <mail@notarealemailaddy.com> wrote:
[color=blue]
> I am inserting values into a row.. works OK
>
> If I try to insert a value into a row that doesnt exist (using where)
> it always returns true the same as if it did work[/color]

You can't use WHERE in an INSERT statement. Doesn't make sense either.
[color=blue]
> I want to update rows that have one unique field.. if the row doesnt
> exists it should return 0 rows updated.. I then create the row...
>
> But it always returns 1 even when I update a row that doesnt exist..
> How do I get an error or a false return?[/color]

Use mysql_affected_rows() after the UPDATE statement - this returns 0 if
no record was updated.

HTH;
JOn
  #3  
Old July 17th, 2005, 02:35 AM
Pedro Graca
Guest
 
Posts: n/a

re: Not getting expected MySQL error


KIPAX wrote:[color=blue]
> I want to update rows that have one unique field.. if the row doesnt
> exists it should return 0 rows updated.. I then create the row...[/color]

you can try the (non-standard) REPLACE command
http://www.mysql.com/doc/en/REPLACE.html

It does a DELETE and a INSERT for rows that exist
and a INSERT for rows that don't already exist.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
  #4  
Old July 17th, 2005, 02:35 AM
KIPAX
Guest
 
Posts: n/a

re: Not getting expected MySQL error


On 11 Dec 2003 11:24:30 GMT, Jon Kraft <jon@jonux.co.uk> wrote:

[color=blue][color=green]
>> I am inserting values into a row.. works OK
>>
>> If I try to insert a value into a row that doesnt exist (using where)
>> it always returns true the same as if it did work[/color]
>
>You can't use WHERE in an INSERT statement. Doesn't make sense either.[/color]

I am not.. I am trying to insert values into existing rows. But if
row doesnt exist then i was expecting it to let me know.. I would then
use a normal insert to create a new unique row.. the where was only
used to insert into an existing row.
[color=blue]
>Use mysql_affected_rows() after the UPDATE statement - this returns 0 if
>no record was updated.[/color]


Thats the ticket... Thanks :)


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Expected Error on SMF Forum site tridirk answers 1 September 19th, 2008 07:09 AM
MyISAM engine: worst case scenario in case of crash (mysql, O/S,hardware, whatever) alf answers 110 December 9th, 2006 05:25 PM
Error John D. Sanders answers 3 July 20th, 2005 01:44 AM
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Noel Wood answers 2 July 17th, 2005 09:27 AM