꾸鱗Oracle돨php잚
2018-09-07 14:33
<?
//±쒸멩×:灌쒔冀옵헝蕎踞긱錦맣
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//
// ±匡숭츰×
// ±鱗痰×:Oracle무痰변鑒잚
// ±鱗諒×:莖뿍
//
// ±離빈錦맣휑퍅×:2001/05/11[cxx]
// ±긴좆땍屢방橙×:‘C_=俚륜謹,‘I_=憐謹,‘N_=鑒俚謹,‘L_=꼈랑謹,‘A_=鑒莉謹
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//⊃db_logon()역폘鑒앴욋젯쌈
//⊃db_query()繫痰select
//⊃db_change()鑒앴욋맣긴돨繫痰변鑒(insert,delete,update)
//⊃db_insert()insert,殮쌈딧痰db_change()
//⊃db_delete()delete,殮쌈딧痰db_change()
//⊃db_update()update,殮쌈딧痰db_change()
//⊃db_commit()慤蛟뒵슥
//⊃db_rollback()慤蛟쀼藁
//⊃db_logoff()뙤역鑒앴욋젯쌈
//------------------------------------------------------------------------------------------
Class c_ora_db
{
//------------------------------------------------------------------------------------------
//긴좆땍屢
//------------------------------------------------------------------------------------------
var $C_user= "";//鑒앴욋痰빵츰
var $C_passwd= "";//鑒앴욋왯즈
var $C_db= "";//鑒앴욋츰
var $I_linkID= 0;//젯窟얌깨
var $I_stmtID= 0;//꿴璂얌깨
var $color="";//홍애奈??
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_logon()
//鱗痰:역폘鑒앴욋젯쌈
//꽝鑒:轟
//럿쀼令:젯窟얌깨(憐謹)
//구鬧:轟
//------------------------------------------------------------------------------------------
functiondb_logon()
{
$this->I_linkID =@OCILogon($this->C_user,$this->C_passwd,$this->C_db);
if ($this->I_linkID == 0){AlertExit(鑒앴욋졍쌈呵겨,헝宅DBA젬溝!);}
return$this->I_linkID;
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_query($C_sql,$A_define="",$I_start=-1,$I_end=-1)
//鱗痰:select
//꽝鑒:$C_sqlsql刀얌
//$A_define矜곬땍돨俚뙈。鑒莉謹
//$I_start역迦혤션쩌 -1橙혤놔꿴璂돨杰唐션쩌
//$I_end써監혤셩쩌
//럿쀼令:랗郭鑒莉($A_rs)
//구鬧:繫법鑒俚0,1,2....옵련狂뚤壇俚뙈돨令; 샀繫법꿴璂俚뙈츰冷옵련狂뚤壇俚뙈돨令
//흔繫법$A_rs[0][0]샀$A_rs[0][NAME]샀$A_rs[0][name]떼옵련狂看係션쩌NAME俚뙈
//$I_start,$I_end角토북롸女賈痰돨꽝鑒。
//------------------------------------------------------------------------------------------
functiondb_query($C_sql,$A_define="",$I_start=-1,$I_end=-1)
{
if (!$C_sql){AlertExit("꽝鑒꼇홍!");}//쇱꿴꽝鑒
//젯쌈쇱꿎
if ($this->I_linkID == 0){AlertExit(鑒앴욋졍쌈呵겨,헝宅DBA젬溝!);}
//목駕쇱꿎
$this -> I_stmtID = OCIParse($this -> I_linkID,$C_sql);
if (!$this -> I_stmtID){AlertExit( sql목駕놔댄!헝宅넋埼逃젬溝);}
//흔벎청寧땍곬땍돨俚뙈,橙닖SQL刀얌櫓혼혤
if($A_define=="")
{
$A_Cur = explode("select",$C_sql);
$A_Cur = explode("from",$A_Cur[1]);
$A_define = explode(",",$A_Cur[0]);
}
//곬땍鑒앴욋깊俚뙈
if(gettype($A_define) == "array")//꿴璂죗角鑒莉
{
for($i=0;$i<count($A_define);$i++)
{
$A_define_up[$i] = trim(strtoupper($A_define[$i]));//댕畇깻혼뇜왕목
}
for($i=0;$i<count($A_define_up);$i++)
{
OCIDefineByName($this -> I_stmtID,"$A_define_up[$i]",&$$A_define[$i]);//곬땍
}
}
elseif(trim($A_define) <> "")//꿴璂죗怜唐寧몸
{
$A_define_up = trim(strtoupper($A_define));
OCIDefineByName($this -> I_stmtID,"$A_define_up",&$$A_define);
}
//獵契곬땍봤돨SQL刀얌
if(!OCIExecute($this -> I_stmtID))
{
echo "<font color=red><b>獵契놔댄:</b></font>SQL Error:<font color=red>$C_sql</font><br>";
return false;
}
$lower = 0;//럿쀼랗郭鑒莉돨뒤寧郭苟깃왠齡긴좆
$cnt = 0;//역迦혤鑒깃街
//혤션쩌
while (OCIFetchInto($this -> I_stmtID,&$cur,OCI_ASSOC))
{
//혤꿴璂놔윱돨杰唐션쩌
if ($I_start == -1)
{
if (gettype($A_define) == "array")//꿴璂죗角鑒莉
{
for ($i=0;$i<count($A_define);$i++)
{
if ($cur[$A_define_up[$i]] <> $$A_define[$i])
{
$$A_define[$i] = $cur[$A_define_up[$i]];
}
$A_rs[$lower][$i] = $$A_define[$i];//痰鑒俚련狂
$A_rs[$lower][$A_define[$i]] = $$A_define[$i];//痰鬼硅련狂
$A_rs[$lower][$A_define_up[$i]] = $$A_define[$i];//痰댕畇련狂
}
}
elseif (trim($A_define) <> "")//꿴璂죗怜唐寧몸
{
if ($cur[$A_define_up] <> $$A_define)
{
$$A_define = $cur[$A_define_up];
}
$A_rs[$lower][0] = $$A_define;//痰鑒俚련狂
$A_rs[$lower][$A_define] = $$A_define;//痰鬼畇련狂
$A_rs[$lower][$A_define_up] = $$A_define;//痰댕硅련狂
}
$lower++;//苟깃속寧
}
//혤놔寧땍션쩌(토북롸女賈痰)
if ($I_start <> -1)
{
if ($cnt >= $I_start)
{
$cnt++;
if ($I_end - $I_start <> 0)
{
$I_end--;
if (gettype($A_define) == "array")
{
for($i=0;$i<count($A_define_up);$i++)
{
if ($cur[$A_define_up[$i]] <> $$A_define[$i])
{
$$A_define[$i] = $cur[$A_define_up[$i]];
}
$A_rs[$lower][$i] = $$A_define[$i];//痰鑒俚련狂
$A_rs[$lower][$A_define[$i]] = $$A_define[$i];//痰鬼硅련狂
$A_rs[$lower][$A_define_up[$i]] = $$A_define[$i];//痰댕畇련狂
}
}elseif(trim($A_define) <> "")
{
if ($cur[$A_define_up] <> $$A_define)
{
$$A_define = $cur[$A_define_up];
}
$A_rs[$lower][0] = $$A_define;//痰鑒俚련狂
$A_rs[$lower][$A_define] = $$A_define;//痰鬼硅련狂
$A_rs[$lower][$A_define_up] = $$A_define;//痰댕畇련狂
}
$lower++;
}else
{
break;//흔벎$I_end-$I_start=0깊刻혤供션쩌깻契놔while琦뻔
}
}else
{
$cnt++;//흔벎$cnt<$I_start,$cnt++
}
}
}//while돨써監
//姦렴얌깨깻럿쀼꿴璂鑒앴(寧몸랗郭鑒莉)
OCIFreestatement($this -> I_stmtID);
return $A_rs;
} //function돨써監
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_change($C_sql,$A_bind)
//鱗痰:db change
//꽝鑒:$C_sqlsql刀얌
//$A_bind矜곬땍돨俚뙈。鑒莉謹
//럿쀼令:꼈랑令
//구鬧:insert,delete,update繫痰
//------------------------------------------------------------------------------------------
function db_change($C_sql,$A_bind="")
{
if (!$C_sql){AlertExit("꽝鑒꼇홍!");}//쇱꿴꽝鑒
//젯쌈쇱꿎
if($this -> I_linkID==""){AlertExit("乖쳬돨鑒앴욋攣챈,헝?牘慙瑁Ы但?quot;);}
//목駕쇱꿎
$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;
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_delete($C_sql)
//鱗痰:delete
//꽝鑒:C_sqlsql刀얌
//럿쀼令:꼈랑令
//구鬧:맡변鑒怜角槨죄賈痰殮밖,굶醴딧痰db_change()
//------------------------------------------------------------------------------------------
function db_delete($C_sql)
{
return $this -> db_change($C_sql);
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_insert($C_sql,A_bind)
//鱗痰:insert
//꽝鑒:C_sqlsql刀얌
//A_bind곬땍
//럿쀼令:꼈랑令
//구鬧:맡변鑒怜角槨죄賈痰殮밖,굶醴딧痰db_change()
//------------------------------------------------------------------------------------------
function db_insert($C_sql,$A_bind="")
{
return $this -> db_change($C_sql,$A_bind);
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_update($C_sql,A_bind)
//鱗痰:update
//꽝鑒:C_sqlsql刀얌
//A_bind곬땍
//럿쀼令:꼈랑令
//구鬧:맡변鑒怜角槨죄賈痰殮밖,굶醴딧痰db_change()
//------------------------------------------------------------------------------------------
function db_update($C_sql,$A_bind="")
{
return $this -> db_change($C_sql,$A_bind);
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_commit()
//鱗痰:慤蛟뒵슥
//꽝鑒:轟
//럿쀼令:꼈랑令
//구鬧:轟
//------------------------------------------------------------------------------------------
function db_commit()
{
return(OCICommit($this->I_linkID));
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_rollback()
//鱗痰:慤蛟쀼藁
//꽝鑒:轟
//럿쀼令:꼈랑令
//구鬧:轟
//------------------------------------------------------------------------------------------
function db_rollback()
{
return(OCIRollback($this->I_linkID));
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//변鑒츰:db_logoff()
//鱗痰:뙤역鑒앴욋젯쌈
//꽝鑒:轟
//럿쀼令:꼈랑令
//구鬧:轟
//------------------------------------------------------------------------------------------
function db_logoff()
{
return (OCILogoff($this->I_linkID));
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
}
?>
上一篇:MVC模式的PHP实现
下一篇:用php发送带附件的Email