Connecting Tech Pros Worldwide Help | Site Map

Not getting expected MySQL error

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 01:35 AM
KIPAX
Guest
 
Posts: n/a
Default Not getting expected MySQL error



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, 01:35 AM
Jon Kraft
Guest
 
Posts: n/a
Default 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, 01:35 AM
Pedro Graca
Guest
 
Posts: n/a
Default 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, 01:35 AM
KIPAX
Guest
 
Posts: n/a
Default 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 :)


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.