//------------------------------------------------------------------------------------------ // 函數名:db_change($C_sql,$A_bind) // 作 用:db change // 參 數:$C_sql sql語句 // $A_bind 需綁定的字段。數組型 // 返回值:布爾值 // 備 注:insert,delete,update通用 //------------------------------------------------------------------------------------------ function db_change($C_sql,$A_bind="") { if (!$C_sql){AlertExit("參數不全!");}//檢查參數 //連接檢測 if($this -> I_linkID==""){ AlertExit("我們的數據庫正忙,請稍后再連接!");} //格式檢測 $this -> I_stmtID = OCIParse($this -> I_linkID,$C_sql); if (!$this -> I_stmtID){AlertExit( sql格式出錯!請與程序員聯系);} //綁定 if(gettype($A_bind) == "array") { for($i=0;$i<count($A_bind);$i++) { global $$A_bind[$i]; $$A_bind[$i] = StripSlashes($$A_bind[$i]); //去掉反斜線字元 $$A_bind[$i] = str_replace("<?","< ?",$$A_bind[$i]); //過濾掉PHP標示 } for($i=0;$i<count($A_bind);$i++){ OCIBindByName($this -> I_stmtID, ":$A_bind[$i]", &$$A_bind[$i], -1); //綁定 } } elseif(trim($A_bind) <> "") //不是數組,是字符 { global $$A_bind; $$A_bind = StripSlashes($$A_bind); $$A_bind = str_replace("<?","< ?",$$A_bind); //過濾掉PHP標示 OCIBindByName($this -> I_stmtID, ":$arrBind", &$$A_bind, -1); } //執行并檢測是否成功 if(!OCIExecute($this -> I_stmtID,OCI_DEFAULT)) { echo "<font color=red><b>執行出錯:</b></font>SQL Error:<font color=red>$C_sql</font><br>"; return false; } /*//傳回受影響的行數 global $I_changenum; $I_changenum = OCINumrows($this -> I_stmtID);*/ //釋放句柄,傳回值 OCIFreeStatement($this -> I_stmtID); return true; }
1 回答

茅侃侃
TA貢獻1842條經驗 獲得超21個贊
$C_sql 應該類似于 insert table(f1, f2, f3, ...) values(:f1, :f2, :f3, ...)
$A_bind: array('123', 'abc', 'ddd', ...)
- 1 回答
- 0 關注
- 400 瀏覽
添加回答
舉報
0/150
提交
取消