dongyi9330 2012-06-03 18:58 采纳率: 100%
浏览 33

交易和PHP

I have been trying to make such functionality that will make sure that on click all the values are being stored in the multiple tables of the database successfully. I read an article about it and it says :

" In PHP there are no such methods and the we must use the direct SQL. (In PHP PDO there are such methods.) "

Kindly let me know is it possible to embed begin transaction and end transaction in an sql query only because i never worked on PDO and the only idea i have is to make multiple insertion to tables in one SQL query.

Rough idea

<?php
$sql = " 
Begin Transaction
insert into .............
insert into ...........
End Transaction "
mysql_query($sql) ?>

SOLUTION THAT I FOUND:

mysql_select_db($database_dany, $dany);
  if (mysql_query('BEGIN')) {
    if (
        mysql_query($query1)  &&
        mysql_query($query2)  &&
        mysql_query($query3) &&
        mysql_query($insertSQL) 
        )
        $result = mysql_query('COMMIT'); // both queries looked OK, save
    else
    {
        mysql_query('ROLLBACK'); // problems with queries, no changes
        echo "There are some problemo!!!";
        }
  • 写回答

2条回答 默认 最新

  • douan6931 2012-06-03 19:01
    关注

    That will vary based on the db that you use. The mysql documentation page on the subject: http://dev.mysql.com/doc/refman/5.5/en/commit.html

     START TRANSACTION;
     SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
     UPDATE table2 SET summary=@A WHERE type=1;
     COMMIT;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错