普通网友 2012-07-31 14:57
浏览 53
已采纳

如何将多个查询从mssql_ *转换为PDO mysql

I have little php code for daily audit transaction.I make simple to get the point.

$result = mssql_query("BEGIN TRAN");    
$result = mssql_query("insert into items_history (select * from items)");   //move transaction to history
$result = mssql_query("delete * from items)");                                  //clear transaction table for new month transaction
$result = mssql_query(                                                          //get the data for used in another script 
            "select items_history.item_id,
                items_history.item_name,
                group_items.group_name 
            from 
                items_history,group_items 
            where group_items.id=items_history.id and 
                day(items_history.date_trans)=day(items_history.date_trans)-1 "                     // whit where include 
            );
$result = mssql_query("update trans_control set current_day=current_day+1"  };  //update the system date to next day

if (!$result) {
     mssql_query("ROLLBACK TRAN");
    } else {
     mssql_query("COMMIT TRAN");
    }
mssql_close();

For some reason, this database need to store online with mysql database. in offline, i am not much wory about secure with this code. But in online, it make me think allot about secure. And now i want to convert this script in to PDO MySql. the goal is simple with more secure:

$result = q("BEGIN");   
$result = q("qry1");
$result = q("qry2");
$result = q("qry3");// select with many join table and some parameter data in where like 'string','int', 'date', and maybe with "Union All" in select
$result = q("qry..."};

if (!$result) {
     q("ROLLBACK");
    } else {
     q("COMMIT");
    }

If another question have problem same like this. I am glade to start with that, specially simple wrapper, so i can learn how it work. thank you to before.

  • 写回答

1条回答 默认 最新

  • du060334 2012-07-31 15:02
    关注

    The security should be no problem as long as you use bound parameters, see www.php.net/manual/en/pdostatement.bindparam.php and http://www.php.net/manual/en/pdostatement.bindvalue.php

    And for your transactions you can emulate the same thing by using these methods:

    http://www.php.net/manual/en/pdo.begintransaction.php instead of your BEGIN TRAN query, http://www.php.net/manual/en/pdo.commit.php instead of COMMIT, http://www.php.net/manual/en/pdo.rollback.php instead of ROLLBACK

    But if the queries are exactly the ones from your first code sample I don't see any external parameters that could cause security issues

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?