| | |
Rows affected in mysql
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2009
Posts: 11
Reputation:
Solved Threads: 0
Hi bhanu1225,
Thanks! Actually, am trying to update a record say: update tbl_name set name='bhanu1225' where name='pradeep' and id='1';
If the update is success, i want to print a messgae 'successfully updated' in frontend. For this i want to know if a record is updated in database or not. Am using mysql and jsp.
Thanks,
Thanks! Actually, am trying to update a record say: update tbl_name set name='bhanu1225' where name='pradeep' and id='1';
If the update is success, i want to print a messgae 'successfully updated' in frontend. For this i want to know if a record is updated in database or not. Am using mysql and jsp.
Thanks,
Hi.
The ROW_COUNT function will return the number of rows in a previous INSERT, UPDATE or DELETE statement.
The ROW_COUNT function will return the number of rows in a previous INSERT, UPDATE or DELETE statement.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
Ok.
It seems query browser executes queries on separate connections, or something like that, so when you execute a
An easy fix is to just create a wrapper procedure.
For example:
Which you could then call like:
Which returns a single field for 'Affected rows' with the value 2.
It seems query browser executes queries on separate connections, or something like that, so when you execute a
INSERT/UPDATE/DELETE and then a SELECT ROW_COUNT(); query, the data from the latter will no longer be available to the function.An easy fix is to just create a wrapper procedure.
For example:
mysql Syntax (Toggle Plain Text)
DELIMITER $$ DROP PROCEDURE IF EXISTS `test`.`rc_exec`$$ CREATE PROCEDURE `test`.`rc_exec` (IN command VARCHAR(60000)) BEGIN SET @query = command; PREPARE stmt FROM @query; EXECUTE stmt; SELECT ROW_COUNT() AS 'Affected rows'; END$$ DELIMITER ;
mysql Syntax (Toggle Plain Text)
CALL rc_exec(" INSERT INTO myTable(First, Second) VALUES ('Testing First', 'Testing Second'), ('Testing First again', 'Teststing Second again');");
Last edited by Atli; Jun 19th, 2009 at 5:00 am.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
The
Keep in mind that the query browser is just a development tool. It doesn't execute queries the same way a PHP or JSP script would. They wouldn't need the procedure to use the ROW_COUNT function.
For example, this would print "3":
And I'm sure the JSP equivalent for that would to.
And in languages like those, you don't actually have to use the ROW_COUNT function. They have functions like the
The ROW_COUNT function isn't really mean to be used like this.
It's more aimed at procedures and such.
ROW_COUNT function is the mysql_affected_rows equivalent in MySQL.Keep in mind that the query browser is just a development tool. It doesn't execute queries the same way a PHP or JSP script would. They wouldn't need the procedure to use the ROW_COUNT function.
For example, this would print "3":
php Syntax (Toggle Plain Text)
<?php $inResult = mysql_query("INSERT INTO tbl VALUES()()()"); $rcResult = mysql_query("SELECT ROW_COUNT()"); $count = mysql_result($rcResult, 0, 0); echo $count; ?>
And in languages like those, you don't actually have to use the ROW_COUNT function. They have functions like the
mysql_num_rows function.The ROW_COUNT function isn't really mean to be used like this.
It's more aimed at procedures and such.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
![]() |
Similar Threads
- help with mysql bindings (Python)
- Getting mysql "UNaffected" rows (PHP)
- what's wrong in this code? (PHP)
- Creating a login page in PHP (PHP)
- insert values to mysql database (JSP)
- Its really a problem on INSERT statement (MySQL)
- FULLTEXT searching (MySQL)
Other Threads in the MySQL Forum
- Previous Thread: Return zero if query returns nothing?
- Next Thread: help with (hopefully) simple nested query
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





