同时操作不同库里表,支持事物吗,mysql
MYSQL数据库
有数据库A和数据库B,同时操作A中两张表和B中两张表,支持事物回滚么,都是innodb。。
分两种情况
A库和B库在同一台服务器
A库和B库不在同一台服务器
请教大神
------解决思路----------------------
A库和B库在同一台服务器
A库和B库不在同一台服务器
两个都支持事务。
可以使用分布式事务
<br />public function testAction(){<br /> $goods_id=1;<br /> $goods_name = "大西瓜";<br /> $num = 1;<br /> $rs_order = $this->test->createorder($goods_id,$goods_name,$num);<br /> $rs_goods = $this->test->deduction($goods_id,$num);<br /> if($rs_order['status'] =="success" && $rs_goods['status']=="success"){<br /> $this->test->commitdb($rs_order['XA']);<br /> $this->test->commitdb1($rs_goods['XA']);<br /> }else{<br /> $this->test->rollbackdb($rs_order['XA']);<br /> $this->test->rollbackdb1($rs_goods['XA']);<br /> }<br /> <br /> print_r($rs_order);<br /> echo "<br />";<br /> print_r($rs_goods);<br /> die("dddd");<br /> }<br /> <br /> public function createorder($goods_id,$goods_name,$num){<br /> $XA = uniqid("");<br /> $this->_db->query("XA START '$XA'");<br /> $_rs = true;<br /> try {<br /> $data = array();<br /> $data['order_id'] = "V".date("YmdHis");<br /> $data['goods_name'] = $goods_name;<br /> $data['goods_num'] = $num;<br /> $this->_db->insert("temp_orders",$data);<br /> $rs = $this->_db->lastInsertId();<br /> if($rs){<br /> $_rs = true;<br /> }else{<br /> $_rs = false;<br /> }<br /> } catch (Exception $e) {<br /> $_rs = false;<br /> }<br /> $this->_db->query("XA END '$XA'");<br /> if($_rs){<br /> $this->_db->query("XA PREPARE '$XA'");<br /> return array("status"=>"success","XA"=>$XA);<br /> }else{<br /> return array("status"=>"nosuccess","XA"=>$XA);<br /> }<br /> }<br /> <br /> public function deduction($id){<br /> $XA = uniqid("");<br /> $this->db1->query("XA START '$XA'");<br /> $last_rs = true;<br /> try {<br /> $sql = "select * from temp_goods where id = '$id' and goods_num>0";<br /> $rs = $this->db1->fetchRow($sql);<br /> if(!empty($rs)){<br /> $sql = "update temp_goods set goods_num = goods_num-1 where id = '$id'";<br /> $rd = $this->db1->query($sql);<br /> if($rd){<br /> $last_rs = true;<br /> }else{<br /> $last_rs = false;<br /> }<br /> }else{<br /> $last_rs = false;;<br /> }<br /> } catch (Exception $e) {<br /> $last_rs = false;;<br /> }<br /> $this->db1->query("XA END '$XA'");<br /> <br /> if($last_rs){<br /> $this->db1->query("XA PREPARE '$XA'");<br /> return array("status"=>"success","XA"=>$XA);<br /> }else{<br /> return array("status"=>"nosuccess","XA"=>$XA);<br /> }<br /> <br /> }<br /> //提交事务!<br /> public function commitdb($xa){<br /> return $this->_db->query("XA COMMIT '$xa'");<br /> }<br /> <br /> //回滚事务<br /> public function rollbackdb($xa){<br /> return $this->_db->query("XA ROLLBACK '$xa'");<br /> }<br /> <br /> //提交事务!<br /> public function commitdb1($xa){<br /> return $this->db1->query("XA COMMIT '$xa'");<br /> }<br /> <br /> //回滚事务<br /> public function rollbackdb1($xa){<br /> return $this->db1->query("XA ROLLBACK '$xa'");<br /> }<br /><br />
参考:http://javalifuqing.blog.163.com/blog/static/83699035201341645329839/

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

Setting the httponly flag is crucial for session cookies because it can effectively prevent XSS attacks and protect user session information. Specifically, 1) the httponly flag prevents JavaScript from accessing cookies, 2) the flag can be set through setcookies and make_response in PHP and Flask, 3) Although it cannot be prevented from all attacks, it should be part of the overall security policy.

PHPsessionssolvetheproblemofmaintainingstateacrossmultipleHTTPrequestsbystoringdataontheserverandassociatingitwithauniquesessionID.1)Theystoredataserver-side,typicallyinfilesordatabases,anduseasessionIDstoredinacookietoretrievedata.2)Sessionsenhances

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
