How we can use mysql_affected_rows()
in stored procedure..
example
BEGIN
DECLARE countRow INT;
DECLARE roomTypeId INT;
INSERT INTO room_type (room_type)
SELECT * FROM (SELECT paramRoomType) AS tmp
WHERE NOT EXISTS (
SELECT room_type_id FROM room_type WHERE room_type = paramRoomType
) LIMIT 1;
SET countRow = ROW_COUNT();
IF(countRow > 0) THEN
SET roomTypeId = LAST_INSERT_ID();
INSERT hotel_has_room_type (hotel_id,room_type_id) VALUES (paramHotelId,roomTypeId);
END IF;
END
Use the ROW_COUNT() information function.
ROW_COUNT() returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE, DELETE, or INSERT. For other statements, the value may not be meaningful.
The ROW_COUNT() value is the same as the value from the mysql_affected_rows() C API function and the row count that the mysql client displays following statement execution.
You cannot use mysql_affected_rows()
in a stored procedure since it's a C API function. You can use FOUND_ROWS()
function which gives a similar functionality. Refer this link for more details.