MYSQL DB SYN

来源:互联网 发布:algorithm基础算法 编辑:程序博客网 时间:2024/06/04 00:51

In mysql, you run these commands on your DB handle before runningy our queries the tables will auto lock :

begin work;

You then run your queries or have codeigniter run your various selects and updates using that db handle.

Then you either

commit;

or

rollback;

Any rows you select from will be locked and can't be read by other processes. If you specifically want the rows to still be readable,you can do:

Select ... IN SHARE MODE

From Mysql docs:

http://dev.mysql.com/doc/refman/5.5/en/select.html

If you use FOR UPDATE with a storage engine that uses page or rowlocks, rows examined by the query are write-locked until the end ofthe current transaction. Using LOCK IN SHARE MODE sets a sharedlock that permits other transactions to read the examined rows butnot to update or delete them. See Section 13.3.9.3, “SELECT ... FORUPDATE and SELECT ... LOCK IN SHARE MODE Locking Reads”.

Another person said this in comments already, but from the CIdocs:

$this->db->trans_start();$this->db->query('AN SQL QUERY...');$this->db->query('ANOTHER QUERY...');$this->db->query('AND YET ANOTHER QUERY...');$this->db->trans_complete(); 

trans_start and trans_complete will run those queries for you onyour handle...

there is probably a trans_rollback too...


0 0
原创粉丝点击