[英]how to convert multiple query from mssql_* to PDO mysql
我有日常審計transaction.I進行簡單的獲得分數少的PHP代碼。
$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();
由於某種原因,該數據庫需要與mysql數據庫一起在線存儲。 在離線狀態下,我對使用此代碼的安全性並不十分擔心。 但是在網上,這讓我想到了關於安全性的分配。 現在我想將此腳本轉換為PDO MySql。 目標簡單,安全性高:
$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");
}
如果另一個問題有這樣的問題。 我很樂意從此開始,特別是簡單的包裝器,這樣我就可以了解它的工作原理。 謝謝你以前。
只要您使用綁定參數,安全性就不會有問題,請參閱www.php.net/manual/zh-cn/pdostatement.bindparam.php和http://www.php.net/manual/zh-cn/pdostatement.bindvalue.php
對於您的交易,您可以使用以下方法模擬相同的事物:
http://www.php.net/manual/en/pdo.begintransaction.php而不是BEGIN TRAN查詢, http ://www.php.net/manual/en/pdo.commit.php而不是COMMIT, http ://www.php.net/manual/en/pdo.rollback.php而不是ROLLBACK
但是,如果查詢恰好是您第一個代碼示例中的查詢,那么我看不到任何可能導致安全問題的外部參數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.