php事务处理后怎样进行页面跳转
我用的是smarty模板,中间需要一个事务处理,同时想数据库插入两条数据,而且必须是成功都成功,失败都失败。
开始我用的是mysql_query('begin');
????????????????? mysql_query($sql);
????????????????? mysql_query($sql);
然后一个if判断,都为true的话commit,否则rollback。最后
????????????????? mysql_query('end');
但是在end之后我要进行一个php页面的跳转,加上end后,end以后的php代码都不执行了,数据添加成功与否页面都不尽兴跳转了。
?
?
?
然后我用set autocommit??? ,把自动提交设置成手动,但是和上边情况一样。。。
?
?
后来我写了一个方法,定义一个全局变量想通过全局变量来判断是否成功,但是这个全局变量的值在方法中确实被改变了,但在方法结束后这个值没有传出来,在外边用var_dump($tranResult),一直都是一个空白的值。。。。。。
?
??? function tranType1($type,$product_name,$pic_name,$name,$diameter,$capacity,$pic){
??? ???? ??? global $tranResult;
??? ???? ???
??? ???? ??? $this->db->query('begin');
??? ???? ??? $main_id = $this->addInfoTable1($type,$product_name,$pic_name);?? //这两个是我写的添加信息的方法,返回的是mysql_insert_id()
??? ???? ??? $addTab2 = $this->addInfoTub($main_id,$name,$diameter,$capacity);
??? ???? ??? if(($main_id !== false) && ($addTab2 !== false) ){
??? ??? ??? ??? $upPic = $this->comm->checkPic($pic);
??? ??? ??? ??? if($upPic){ ???
??? ??? ??? ??? ? $this->db->query('commit');??? ??? ??? ???
??? ??? ??? ??? ? $tranResult = true;
??? ??? ??? ??? ? //var_dump($tranResult);
??? ??? ??? ??? }else{
??? ??? ??? ??? ? $this->db->query('rollback');
??? ??? ??? ??? }
??? ??? ??? }else{
??? ??? ??? ??? ?$this->db->query('rollback');
??? ??? ??? }
??? ??? ???
??? ??? ??? $this->db->query('end');
??? ??? ??? var_dump($tranResult);
??? ?}
?
?
?
?
?
小弟实在想不出解决的方案了,请各位大侠来帮忙解决一下,万分感谢!!!

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad

Dependency injection provides object dependencies through external injection in PHP, improving the maintainability and flexibility of the code. Its implementation methods include: 1. Constructor injection, 2. Set value injection, 3. Interface injection. Using dependency injection can decouple, improve testability and flexibility, but attention should be paid to the possibility of increasing complexity and performance overhead.

Implementing dependency injection (DI) in PHP can be done by manual injection or using DI containers. 1) Manual injection passes dependencies through constructors, such as the UserService class injecting Logger. 2) Use DI containers to automatically manage dependencies, such as the Container class to manage Logger and UserService. Implementing DI can improve code flexibility and testability, but you need to pay attention to traps such as overinjection and service locator anti-mode.

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati


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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
