新聞中心
以下的文章主要向大家描述的是PHP + MySQL事務操作的實際應用代碼演示,我們大家都知道在實際LAMP的應用中,一般PHP所使用的是AdoDB來對MySQL數(shù)據(jù)庫進行操作,下面給出AdoDB相應的代碼方便大家查閱:

成都創(chuàng)新互聯(lián)公司是專業(yè)的東城網(wǎng)站建設(shè)公司,東城接單;提供網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行東城網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
- // ...
- $adodb->startTrans();
實際,getOne所調(diào)用的查詢也可以直接放到rowLock來進行,這里只是為了演示效果能更明顯些。
- $adodb->rowLock('book', 'book_id = 123');
- $bookNumber = $adodb->getOne("SELECT book_number FROM book WHERE book_id = 123");
- $adodb->execute("UPDATE book SET book_numberbook_number = book_number - 1 WHERE book_id = 123");
- $adodb->completeTrans();
- // ...
- ?>
其中,rowLock的方法就是調(diào)用的FOR UPDATE來實現(xiàn)的行鎖,你可能會想把“FOR UPDATE”直接寫到$adodb->getOne()調(diào)用的那條SQL語句里面去實現(xiàn)行鎖的功能,不錯,那樣確實可以,但是并不是所有的數(shù)據(jù)庫都使用“FOR UPDATE”語法來實現(xiàn)行鎖功能,比如Sybase使用“HOLDLOCK”的語法來實現(xiàn)行鎖功能,所以為了你的數(shù)據(jù)庫抽象層保持可移植性,我還是勸你用rowLock來實現(xiàn)行鎖功能,至于可移植性就交給AdoDB好了,嗯,有點扯遠了,今兒就說到這里了。
上述的相關(guān)內(nèi)容就是對PHP + MySQL事務操作的代碼演示的描述,希望會給你帶來一些幫助在此方面。
附:
AdoDB中存在一個setTransactionMode()方法,能夠設(shè)置事務的隔離級別,如下:
- SetTransactionMode allows you to pass in the transaction mode to use for all
subsequent transactions for that connection session. Note: if you have persistent
connections and using mysql or mssql, you might have to explicitly reset your
transaction mode at the beginning of each page request. This is only supported in postgresql,
mssql, mysql with InnoDB and oci8 currently. For example:- $db->SetTransactionMode("SERIALIZABLE");
- $db->BeginTrans();
- $db->Execute(...); $db->Execute(...);
- $db->CommiTrans();
- $db->SetTransactionMode(""); // restore to default
- $db->StartTrans();
- $db->Execute(...); $db->Execute(...);
- $db->CompleteTrans();
- Supported values to pass in:
- * READ UNCOMMITTED (allows dirty reads, but fastest)
- * READ COMMITTED (default postgres, mssql and oci8)
- * REPEATABLE READ (default mysql)
- * SERIALIZABLE (slowest and most restrictive)
以上的相關(guān)內(nèi)容就是對PHP + MySQL事務操作的代碼演示的介紹,望你能有所收獲。
【編輯推薦】
- MySQL命令導數(shù)據(jù)的實際操作與代碼
- MySQL基本操作,新手入門寶典
- MySQL常用命令大匯總
- MySQL數(shù)據(jù)庫安全設(shè)置的操作流程
- 實現(xiàn)MySQL 用戶密碼的設(shè)置步驟
當前題目:PHP + MySQL事務操作的實際應用代碼演示
文章路徑:http://www.5511xx.com/article/cdpscco.html


咨詢
建站咨詢
