472,962 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,962 software developers and data experts.

Rows affected?

Hi,

I am executing an update-query. Is there a way I would get a result if there
is a row affected, because if the row isn't affected (product may not exist)
I have to execute a insert-query. This way I could use 1 query (in the
update-case). Else I would always have to execute 2 query's (1 count-query
and 1 insert or update query).

Thnxz...
Jul 16 '05 #1
2 3157
no spam wrote:
Hi,

I am executing an update-query. Is there a way I would get a result if
there is a row affected, because if the row isn't affected (product may
not exist) I have to execute a insert-query. This way I could use 1 query
(in the update-case). Else I would always have to execute 2 query's (1
count-query and 1 insert or update query).

Thnxz...


http://dk.php.net/manual/en/function...ected-rows.php

Should give you a hint.
That it says dk.php.net is only due to the local mirror.

/Andreas
--
Registeret Linux user #292411
Jul 16 '05 #2
thnxz... mysql_affected_rows() was the function. Totally forgot the
mysql-functions...

"Eivind Lie Nitter" <el*@gmx.net> schreef in bericht
news:1fz4bvf.ick75z156nw93N%el*@gmx.net...
Roger Godefroy <godefroy@(nospam)home.nl> wrote:
Hi,

I am executing an update-query. Is there a way I would get a result if there is a row affected, because if the row isn't affected (product may not exist) I have to execute a insert-query. This way I could use 1 query (in the
update-case). Else I would always have to execute 2 query's (1 count-query and 1 insert or update query).

Thnxz...


If you are using MySQL:

mysql_query("update table set bla='bla' where id=17");

if (mysql_affected_rows() == 0) {

mysql_query("insert ...");

}

Should work :)

--
Eivind Lie Nitter
el*@gmx.net
http://ununique.net

Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: RotterdamStudents | last post by:
Hello there, i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',...
5
by: Chris Stromberger | last post by:
When issuing updates in mysql (in the console window), mysql will tell you if any rows matched and how many rows were updated (see below). I know how to get number of rows udpated using MySQLdb,...
2
by: Gnurp Gnarp | last post by:
When the number of columns get large, it becomes increasingly difficult to view the results of a select in a small window (e.g. 80 line xterm) because of line wrapping. Can I have the results of...
1
by: dkode8 | last post by:
Heres my problem, the first part selects a row from the database, if there is no row with the criteria it inserts a row and then returns it, the problem is the IF statement that inserts the row,...
2
by: Kiki | last post by:
Hi, just a small question. I've just looked at a friends code and he's done this: int rowsAffected = sql.ExecuteNonQuery("stored_procedure", cmdParams); if(rowsAffected < 1) { return false; }...
4
by: kenfar | last post by:
I've got a batch etl process in which I typically wrap DML with selects in order to capture the number of rows affected. For example: SELECT 'rows updated', COUNT(*) FROM NEW TABLE ( UPDATE...
3
by: Carl K | last post by:
using MySQLdb, I do cursor.execute("update...") How can I tell how many rows were affected ? Carl K
3
by: senthilnova | last post by:
hi all i have c# class which calls a stored procedure having insert,update and delete method (using if to switch between them). when i call the SP to EXECUTENONQUER() there is no response from...
0
by: shashi shekhar singh | last post by:
Respected Sir, i want to check it out, when insert returns zero rows affected ? insert into Question_Copy(,column_name1,column_name2,column_name3) SELECT top 1...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.