php鑒앴욋젯쌈
2018-09-07 13:34
繫법PHP콱옵鹿햐漑돨젯쌈돕鑒앴욋,헝헹鑒앴깻쉥페鞫刻瞳콱돨web籃듐櫓,?芻죗貧켁暄駙宿筠켁暄孚?ySQL角寧蘆붤직契돨鑒앴욋,깻할瞳빳젬貢櫓唐冀뜩唐밑PHP宅MySQL돨싱넋。MySQL角출롤돨,侶寧듐冷冀앎俱多죄꼇?謨匣S?黨페밤렉壇痰,乖앎꼇拳瞳侶쟁琉甘MySQL돨賈痰렘랬죄。Oracle굳댕좆瞳폐撚壇痰櫓꽃痰,凜늪乖쳬앎적痰Oracle윱썽??HP宅鑒앴욋돨젯쌈。乖쳬뎠횔꼇삔瓊섟Oracle鑒앴욋돨?雍팸잿,覩凜角侶綠쒔낚놔죄乖쳬돨擎쬠렀鍋。
PHP瓊묩죄좃敬변鑒宅Oracle젯쌈,롸깎角ORA_뵨OCI변鑒。페櫓ORA_변鑒쫠鞫냈앉。OCI변鑒뫘劤앴綱뫘봤寧硅。좃諒돨賈痰刀랬섯빎宮뀌轟섯。흔품杰甘,콱돨PHP갛陋朞淃壇맡옵鹿連넣좃諒돨賈痰。
拳삿돤뫘뜩唐밑瞳MicrosoftWindows틱憩?構꾕겔㎡?HP3돨Apache륩蛟포돨列街鹿섟뫘뜩唐밑Oracle鑒앴욋돨列街,헝꿴敦鹿苟URL:。
4.1젯쌈
if($conn=Ora_Logon("user@TNSNAME","password"))
{
echo"SUCCESS!Connectedtodatabase\n";
}
else
{
echo"Failed:-(Couldnotconnecttodatabase\n";
}
Ora_Logoff($conn);
phpinfo();
?>
鹿?求響胤밉?NSNAME(瞳콱돨tnsnames.ora匡숭櫓寧츠)땍屢돨Oracle鑒앴욋츰냔、痰빵츰냔뵨쵱쯤젯쌈鑒앴욋。瞳냥묘젯쌈돨샘뇟?句?ra_logon변鑒럿쀼寧몸렷쥐돨젯쌈ID깻뇨닸瞳긴좆$conn櫓。
4.2꿴璂
솝?腕胤暄駙叔耭젯쌈앎岐,苟충乖쳬앎윱茄셥돨壇痰뚤鑒앴욋돨꿴璂。苟충돨덜쯤蘿刻죄寧몸젯쌈깻꿴璂돨듕謹절綾:
/*
*젯쌈鑒앴욋깻獵契꿴璂
*/
functionprintoraerr($in_cur)
{
//쇱꿴Oracle角뤠놔댄
//흔벎닸瞳댄轎橙鞫刻
//뎠寧濾굳샴삶珂첼늴헝헹Oracle빈딧痰맡변鑒
if(ora_errorcode($in_cur))
echo"Oraclecode-".ora_error($in_cur)."\n";
return;
}
/**寮넋埼*/
if(!($conn=ora_logon("user@TNSNAME","password")))
{
echo"Connectiontodatabasefailed\n";
exit;
}
echo"Connectedasconnection-$conn
\n";
echo"Openingcursor...
\n";
$cursor=ora_open($conn);printoraerr($cursor);
echo"Openedcursor-$cursor
\n";
$qry="selectuser,sysdatefromdual";
echo"Parsingthequery$qry...
\n";
ora_parse($cursor,$qry,0);printoraerr($cursor);
echo"Queryparsed
\n";
echo"Executingcursor...
\n";
ora_exec($cursor);printoraerr($cursor);
echo"Executedcursor
\n";
echo"Fetchingcursor...
\n";
while(ora_fetch($cursor))
{
$user=ora_getcolumn($cursor,0);printoraerr($cursor);
$sysdate=ora_getcolumn($cursor,1);printoraerr($cursor);
echo"row=$user,$sysdate
\n";
}
echo"Fetchedallrecords
\n";
echo"Closingcursor...
\n";
ora_close($cursor);
echo"Closedcursor
\n";
echo"Loggingofffromoracle...
\n";
ora_logoff($conn);
echo"Loggedofffromoracle
\n";
?>
(陋諒鬧:鹿?求響遺洸궜墓▧界?遺죵三恝?HPManual돨Oracle鑒앴욋변鑒꼬롸)
4.3鞫刻써벎
鹿苟덜쯤蘿刻죄等湳꿴璂鑒앴욋깻쉥써벎渴놔:
functionprintoraerr($in_cur,$conn)
{
//쇱꿴Oracle角뤠놔댄
//흔벎닸瞳댄轎橙鞫刻
//뎠寧濾굳샴삶珂첼늴헝헹Oracle빈딧痰맡변鑒
//Ifitencounteredanerror,weexitimmediately
if(ora_errorcode($in_cur))
{
echo"Oraclecode-".ora_error($in_cur)."
n";
ora_logoff($conn);
exit;
}
return;
}
functionexequery($w_qry,$conn)
{
$cursor=ora_open($conn);printoraerr($cursor,$conn);
ora_parse($cursor,$w_qry,0);printoraerr($cursor,$conn);
ora_exec($cursor);printoraerr($cursor,$conn);
$numrows=0;
$w_numcols=ora_numcols($cursor);
//鞫刻庫꼬
echo"
\n";
for($i=0;$i<$w_numcols;$i++)
{
$align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";
echo"\t".ora_columnname($cursor,$i)."\n";
}
echo"
\n";
while(ora_fetch($cursor))
{
echo"\n";
for($i=0;$i<$w_numcols;$i++)
{
$align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";
if(ora_columntype($cursor,$i)=="LONG")
echo"".
ora_getcolumn($cursor,$i)."
\n";
else
echo"".ora_getcolumn($cursor,$i)."\n";
printoraerr($cursor,$conn);
}
$numrows++;
echo"
\n";
}
if($numrows==0)
echo"Queryreturnednorecords
\n";
else
{
echo"\n";
echo"Count\n";
echo"$numrows\n";
echo"
\n";
}
echo"\n";
ora_close($cursor);
return;
}
//寮넋埼
if(!($conn=ora_logon("user@SID","password")))
{
echo"Error:Cannotconnecttodatabase\n";
exit;
}
$qry="SELECT
deptno\"Dept\"
,empno\"Emp\"
,empnm\"Name\"
,salary\"Salary\"
FROM
employee
ORDERBY1,2";
exequery($qry);
ora_logoff($conn);
?>
(陋諒鬧:鹿?求響遺洸궜墓▧界?遺죵三恝?HPManual돨Oracle鑒앴욋변鑒꼬롸)
4.4샘黨HTTP돨Oracle되쩌
쉥鹿苟덜쯤속瞳PHP女충덜쯤裂품鹿횅훰Oracle되쩌。鬧雷콱극伎攣횅?擁?SID。
if(!isset($PHP_AUTH_USER))
{
Header("
Header("HTTP/1.0401Unauthorized");
$title="LoginInstructions";
echo"
Youarenotauthorizedtoenterthesite
\n";
exit;
}
else
{
if(!($conn=ora_logon("$PHP_AUTH_USER@$SID",$PHP_AUTH_PW)))
{
Header("WWW-authenticate:basicrealm=\"$SID\"");
Header("HTTP/1.0401Unauthorized");
$title="LoginInstructions";
echo"
Youarenotauthorisedtoenterthesite
\n";
exit;
}
}
?>
上一篇:VFP与其他应用程序的集成