By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

Not getting expected MySQL error

P: 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 :)
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
KIPAX <ma**@notarealemailaddy.com> wrote:
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
You can't use WHERE in an INSERT statement. Doesn't make sense either.
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?


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

HTH;
JOn
Jul 17 '05 #2

P: n/a
KIPAX wrote:
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...


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 =--
Jul 17 '05 #3

P: n/a
On 11 Dec 2003 11:24:30 GMT, Jon Kraft <jo*@jonux.co.uk> wrote:

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
You can't use WHERE in an INSERT statement. Doesn't make sense either.


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.
Use mysql_affected_rows() after the UPDATE statement - this returns 0 if
no record was updated.

Thats the ticket... Thanks :)
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.