SmartyʵÀý½ÌѧʵÀýƪ£¨Èý¡¢Ê¹ÓÃADODBÁ¬½ÓÊý¾Ý¿a£(C)
Ç°Á½¸oÔÂÒoΪ¹¤×÷ÉϵÄÔÒoÒ»Ö±ºÜæ,ËuÒÔûÓм°Ê±Íe³ÉÕa¸o½Ì³Ì,ÕýºÃ½ñÌiÖÜÁu²»ÓüӰa,³e¸o¿ÕÍe³ÉËu°É! ÔÚ¿ªÊ¼ÐµĵĽ̵̳Äʱºo,ÎÒ
ÏÈ°ÑÒÔÇ°µÄÎÒдµÄÄǸo½Ì³ÌÖеÄÒ»Ð(C)´iÎoµÄµØ½Ð޸ĹýÀ´,ÔÚÕaÀiÒª¸Ðл nesta2001zhangÐÖµÜ,ÊÇËuÕÒ³oÁËÎÄÕÂÖеÄÒ»Ð(C)´iÎo,ñÔoÕaeµÄ±»±ðÈË
Âi"ÎoÈË×ÓµÜÁË (˵À´ÕaeÊDzÑÀ¢,Îҵijo¸a¢²¼ºoºo¾Í¢ÏÖÔÚÒ»´o¶ÑµÄÎÊÌa,ºoÀ´Ò»Ð(C)ʱºo*¢ÖØÐÂÐ޸ĺoµÄÎļþÖоÓȻҲ³oÏÖÁË´iÎo,ÕaeÊDz»Ó¦
while($db->next_record() && $i > 0)
{
$array[] = array("NewsID", csubstr($db->f("iNewsID"), 0, 20),
"NewsTitle", csubstr($db->f("vcNewsTitle"), 0, 20));
while($db->next_record() && $i > 0)
{
$array[] = array("NewsID" => $db->f("iNewsID"),
"NewsTitle" => csubstr($db->f("vcNewsTitle"), 0, 20));
ΪʲôÕaÑu¸ÄÄØ?ÒoΪµÚ¶þÖÖ½¨¸uÇaÎuÃ÷ÁËÒ»Ð(C),ʵ¼ÊÉϵÚÒ»ÖֽʽËuÖ´ÐеÄЧ¹uÓeµÚ¶þÖÖ½*¨Ã»Ê²Ã´²i±ð,¶øÇÒÄǼ¸¸o³ÌÐoÎÒ¶¼Ôø¾µ÷ÊÔ¹ý,
ûÓÐÈκÎÎÊÌa.
ºÃÁË,ÄÇÎÒÃǽñÌi¾ÍÏÈÀ´ËµËµADODB.˵µ½ADODB,¿ÉÄÜ×o¹ýASPµÄ¶¼ÖªµÀWINDOWSƽ̨µÄADO×e¼þ,µ«ÎÒÃÇÕaÀiµÄADODB²»ÊÇ΢ÈiµÄÄǸoÊý¾Ý¿a²Ù
×÷×e¼þ,¶øÊÇÓÉphpÓiÑÔдµÄÒ»Ì×Êý¾Ý¿a²Ù×÷Àa¿a,ÏÈÈÃÎÒÃÇÀ´¿´¿´Ëuµ¹µ×ÓÐʲôÑuµÄÓŵa.
¹¦ÄÜ»¹ÊǺÜÇ¿´oµÄ,ÓкܶaµÄºÜʵÓõŦÄÜ,ʹÓÃËuµÄÕaÐ(C)¹¦ÄÜ,¿ÉÒÔdz£½±aµÄʵÏÖÎÒÃÇÏeÒªµÄ¹¦ÄÜ.ËuÒÔ¶ÔÓÚÄÇÐ(C)ÀÏ°aûÓÐÌØÊaÒªÇoʱ´o¼Ò²»
*ÀÓÃÓÃËu
Ò»¡¢ÈçºÎµÃµ½ADODB? ËuµÄÔËÐл*¾³ÊÇʲô£¿
´Óhttp://sourceforge.net/project/show...ºphp4.0.5ÒÔÉÏ¡£
¶þ¡¢ÈçºÎ°²×°ADODB?
½aѹÏÂÔػصÄѹËoÎļþ£¬×¢Òa£º´o¼ÒÏÂÔØ»ØÀ´µÄ¸ñʽΪADODB.tar.gz£¬ÕaÊÇlinuxµÄѹËo¸ñʽ£¬ÔÚwindowsÏ´o¼Ò¿ÉÒÔʹÓÃwinrar¶ÔÆa½ø
Ðнaѹ£¬½aѹÍe³Éºo½«Ä¿Â¼¿½±´µ½Ö¸¶¨µÄĿ¼µÄadodbĿ¼Ï£¬ÏñÎÒÔÚÀý×ÓÖн«Ëu¿½±´µ½ÁË/comm/adodb/ÖС£
Èý¡¢ÈçºÎµ÷ÓÃADODB?
ʹÓÃinclude_once ("./comm/adodb/adodb.inc.php");ÕaÐоͲ»ÓÃ˵ÁË°É£¿°uº¬ADODBµÄÖ÷Îļþ¡£
ËÄ¡¢ÈçºÎʹÓÃADODB?
1.½øÐгoʼ»¯£º
ADODB²ÉÓÃ$conn = ADONewConnection();ÕaÑuµÄÓi¾a½øÐгoʼ»¯,¶ÔADODB½øÐгoʼ»¯ÓÐÁ½Öֽʽ£º
µÚÒ»ÖֽʽΪ£º´«Í³½Ê½¡£ÎÒÔÝʱ³ÆËuΪÕa¸oÃu³Æ¡£ËuʹÓõĽ¨Á¢Ò»¸oÐÂÁ¬½ÓµÄ½Ê½ºÜÏñphpÖеıe×¼Á¬½Ó*½Ê½£º
$conn = new ADONewConnection($dbDriver);
$conn->Connect($host, $user, $passwd, $db);
¼oµ¥°É£¿Èç¹uʹÓùýphplibÖеÄdbÀaÓ¦¸Ã¶ÔËuºÜÊiϤµÄ¡£
µÚ¶þÖֽʽ£º²ÉÓÃdsn½Ê½£¬ÕaÑuÊǽ«Êý¾Ý¿aµÄÁ¬½ÓÓi¾aд³ÉÒ»ÌoÓi¾aÀ´½øÐгoʼ»¯£¬dsnµÄд*¨ÓÐΪ£º$dsn =
"DBType://User:Passwd@Host/DBName"; ÆaÖÐDBType±iʾÊý¾Ý¿aÀaÐÍ£¬User±iʾÓû§Ãu£¬PasswdΪÃÜÂe£¬HostΪ*þÎñÆ÷Ãu£¬DBNameΪÊý¾Ý¿aÃu
£¬ÏñÕaÑuÎÒʹÓÃoracleÊý¾Ý¿a£¬Óû§Ãu£ºoracleUser,ÃÜÂeΪoraclePasswd,Êý¾Ý¿aþÎñÆ÷Ϊlocalhost, Êý¾Ý¿aΪoradbµÄdsnÕaÑuд£º
$dsn = "oracle://oracleUser:OraclePasswd@localhost/oradb";
$conn = new ADONewConnection($dsn);
ÕaÖֽʽ¿ÉÄÜ´ÓASPתÐÐÀ´µÄ³ÌÐoÔ±»a¸u¸ÐÐËȤ¡£
ÕaÁ½ÖÖ*½Ê½¶¼¿ÉÒÔʹÓã¬Òª¿´¸oÈËÏ°¹ßÀ´Ñ¡ÓÃÁË.
ADOConnectionÖ¸µÄÊÇÊý¾Ý¿aÁ¬½ÓµÄÀa£¬¶øADORecordSetÖ¸µÄÊÇÓÉADOConnectionÖ´ÐвeѯÓi¾a*µ»ØµÄÊý¾Ý¼¯Àa£¬Ïa¹ØµÄ×ÊÁÏ´o¼Ò¿ÉÒÔ²eѯADODB
ÀaµÄÊÖ²a¡£
3.»u±¾µÄº¯Êý£º
¹ØÓÚADOConnectionÀaµÄÏa¹Ø½¨ÓУº
1.Connect£ºÊý¾Ý¿aÁ¬½Ó½¨£¬ÉϱßÎÒÃǽeÉܹýµÄ¡£¶ÔÓÚmysql»¹ÓÐPConnect£¬ÓePHPÓiÑÔÖеÄÓèһÑu
2.Execute($sql):Ö´ÐвeѯÓi¾a½a¹uµ»ØÒ»¸oADORecordSetÀa¡£
3.GetOne($sql):µ»ØµÚÒ»ÐеĵÚÒ»¸o×Ö¶Î
4.GetAll($sql):µ»ØËuÓеÄÊý¾Ý¡£Õa¸oº¯Êý¿ÉÊÇ´oÓÐÓô¦£¬¼ÇµÃ²»¼ÇµÄÎÒÔÚÒÔÇ°µÄ½Ì³ÌÖÐд¹ØÓÚÐÂÎÅÁбiµÄÊaÈeʱҪ½«ÐeÒªÔÚÒ³ÃaeÏÔʾµÄ
µ±È»£¬ÕaÀiµÄ$connÓ¦¸Ã½øÐгoʼ»¯¹ýÁË£¬²»Öª´o¼Ò¿´Ã÷°×ÁËûÓУ¿ÔÀ´ÎÒÒªÊÖ¹¤´´½¨µÄ¶þάÊý¾ÝÔÚÕaÀiÖ±½ÓʹÓÃGetAll¾ÍÐÐÁË£¡£¡£¡ÕaÒ²ÊÇΪ
ʲôÓÐÈË»a˵ADODB+SmartyÊÇÎÞµÐ×eºÏµÄÔÒoÖ®Ò»ÁË...
4.SelectLimit($sql, $numrows=-1, $offset=-1, $inputarrr=false): *µ»ØÒ»¸oÊý¾Ý¼¯£¬´o¼Ò´ÓÓi¾aÉÏÒ²²»ÄÑ¿´³oËuÊÇÒ»ÌoÏÞÁ¿²eѯÓi
¾a£¬ÓemysqlÓi¾aÖеÄlimit ÓÐÒiÇuͬ¹¤Ö®Ð§£¬À´Ò»¸o¼oµ¥µÄÀý×Ó£º
$rs = $conn->SelectLimit("select iNewsID, vcNewsTitle from tb_news_CH", 5, 1);
¿´Ã÷°×ÁËÂð£¿$rsÖб£´aeµÄÊÇÊý¾Ý¿aÖдӵÚÒ»¼Ç¼¿ªÊ¼µÄ5Ìo¼Ç¼¡£ÎÒÃÇÖªµÀ£¬ÔÚoracleÊý¾Ý¿a²»Ö§³ÖÔÚSQLÓi¾aÖÐʹÓÃlimit£¬µ«ÊÇÎÒÃÇÈç¹uʹ
ÓÃADODBµÄ»°£¬ÄÇÕa¸oÎÊÌa¾ÍÈÝÒ×½a¾o¶aÁË£¡
5.Close():¹Ø±ÕÊý¾Ý¿a£¬ËaȻ˵PHPÔÚÒ³Ãae½aÊøʱ»a×Ô¶¯¹Ø±Õ£¬µ«ÎªÁ˳ÌÐoµÄÍeÕu´o¼Ò»¹ÊÇÒªÔÚÒ³Ãae½aÊø½øÐÐÊý¾Ý¿aµÄ¹Ø±Õ¡£
¹ØÓÚADORecordSet.ADORecordSetΪ$conn->Execute($sql)*µ»ØµÄ½a¹u,ËuµÄ»u±¾º¯ÊýÈçÏÂ:
¸oº¯Êý,ʹÓÃËu¿ÉÒÔµ»ØÒ»¸oname=$nameµÄÏÂÀ²Ëµ¥(»o¶aÑ¡¿o)!!!µ±È»,ËuÊÇÒ»¸oHTMLµÄ×Öu´®,ÕaÊÇÒ»¸oÁiÈ˼¤¶¯µÄºÃ¶«Î÷,$nameÖ¸µÄÊÇ
optionµÄnameÊoÐÔ,$default_strÊÇĬÈÏÑ¡ÖеÄ×Ö´®,$blank1stItemÖ¸³oµÚÒ»ÏiÊÇñΪ¿Õ,$multiple_selectÖ¸³oÊÇñΪ¶aÑ¡¿o,¶øÎÒÃǵõ½Õa¸o
$rs = &$conn->Exceute($sql);
if($rs)
{
while($rs->EOF)
{
$array[] = array("NewsID" => $rs->fields["iNewsID"],
"NewsTitle" => csubstr($rs->fields["vcNewsTitle"]), 0, 20);
$rs = &$conn->Exceute($sql);
if($rs)
{
while($row = $rs->FetchRow())
{
$array[] = array("NewsID" => $row["iNewsID"],
"NewsTitle" => csubstr($row["vcNewsTitle"]), 0, 20);
}
}