OF COURSE you should use a STORED PROCEDURE!
Trivial.
Example:
Code:
mysql> select * from foo;
+-----------+-------+
| viewcount | name |
+-----------+-------+
| 0 | adam |
| 0 | bob |
| 0 | candy |
+-----------+-------+
mysql> delimiter //
mysql> create procedure getAndBumpCount( nm varchar(20) )
-> begin
-> update foo set viewcount = viewcount + 1 where name = nm;
-> select * from foo where name = nm;
-> end;
-> //
mysql> delimiter ;
mysql> call getAndBumpCount ('candy');
+-----------+-------+
| viewcount | name |
+-----------+-------+
| 1 | candy |
+-----------+-------+
mysql> call getAndBumpCount ('candy');
+-----------+-------+
| viewcount | name |
+-----------+-------+
| 2 | candy |
+-----------+-------+
mysql> call getAndBumpCount('adam');
+-----------+------+
| viewcount | name |
+-----------+------+
| 1 | adam |
+-----------+------+
mysql> select * from foo;
+-----------+-------+
| viewcount | name |
+-----------+-------+
| 1 | adam |
| 0 | bob |
| 2 | candy |
+-----------+-------+
How hard is that?
Why do you thing executing via
CALL would be a bad thing, FouLu? Most DB experts would tell you that you should do *ALL* work via Stored Procedures and not give the casual DB client permissions to use anything *except* Stored Procs!