ADODB½áºÏSMARTYʹÓÃ~³¬¼¶Ç¿

5年以前  |  阅读数:370 次  |  编程语言:PHP 

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));

$i--;
}

Ó¦¸Ã¸u¸ÄΪ£º

while($db->next_record() && $i > 0)
{
$array[] = array("NewsID" => $db->f("iNewsID"),
"NewsTitle" => csubstr($db->f("vcNewsTitle"), 0, 20));

$i--;
}

ΪʲôÕ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.

  1. ÒÔ±e×¼µÄSQLÓi¾aÊeдµÄÊý¾Ý¿aÖ´ÐдuÂeÔÚ½øÐÐÊý¾Ý¿aÒÆֲʱ²»Óøu¸ÄÔ´³ÌÐo,Ò²¾ÍÊÇ˵Ëu¿ÉÒÔÖ§³Ö¶aÖÖÊý¾Ý¿a,°uÀ¨ACCESS.
  2. Ìa¹(C)Óe΢ÈiADODBÏaËƵÄÓi*¨¹¦ÄÜ.ÕaÒ»µa¶ÔÓÚ´ÓASPתÐе½PHPµÄÈËÃÇÊÇÒ»´o¸£Òo,ËuµÄºÜ¶a²Ù×÷¶¼ÓeWINDOWSÖеÄADODBÏaËÆ.
  3. ¿ÉÒÔÉu³ÉSmartyÑ­»ÐeÒªµÄ¶þάÊý×e,ÕaÑu»a¼o»¯smarty¿ª¢.ÕaÒ»µaÊǵȻaÎÒ¸ø´o¼ÒÑÝʾ.
  4. Ö§³ÖÊý¾Ý¿aµÄ»º´ae²eѯ£¬×i´o¿ÉÄܵÄÌa¸ß²eѯÊý¾Ý¿aµÄËٶȡ£
  5. ÆaËuµÄʵÓù¦ÄÜ.
    ËaȻ˵ÓŵaºÜ¶a,µ«ÊÇÓÉÓÚÕa¸oÀa¿a*dz£µÄÅÓ´o,¹aËuµÄÖ÷Ö´ÐÐÀa¾Í107K,ËuÒÔÈç¹u´o¼Ò¿¼ÂÇÖ´ÐÐЧÂʵĻ°¾ÍÒªÈÏÕaeÏeÏeÁË.²»¹ý˵ʵ»°,ËuµÄ

¹¦ÄÜ»¹ÊǺÜÇ¿´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ÈËÏ°¹ßÀ´Ñ¡ÓÃÁË.

  1. Ïa¹ØµÄ¸ÅÄi£º
    ʹÓÃADODBÓÐÁ½¸o»u±¾µÄÀa£¬Ò»ÊÇÊÇADOConnectionÀa£¬ÁiÒ»¸oÊÇADORecordSetÀa£¬Ê¹ÓùýASPµÄÈË¿´µ½ÕaÁ½¸oÀa»aÃ÷°×ËuµÄº¬Òa£¬

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ÏÔʾµÄ

ÐÂÎÅÁбi×o³ÉÒ»¸o¶þάÊý×e£¿¾ÍÊÇÕaÑuµÄÓi¾a£º

while($db->next_record())
{
$array[] = array("NewsID" => $db->f("iNewsID"),
"NewsTitle" => csubstr($db->f("vcNewsTitle"), 0, 20));
}

ÕaÒ»ÐÐÊÇʲôÒa˼ÄØ£¿¾ÍÊǽ«ÒªÏÔʾµÄÐÂÎÅÀý±iÉu³É
$array[0] = array("NewsID"=>1, "NewsTitle"=>"ÕaÀiÐÂÎŵĵÚÒ»Ìo");
$array[1] = array("NewsID"=>2, "NewsTitle"=>"ÕaÀiÐÂÎŵĵڶþÌo");
...
ÕaÑuµÄÐÎʽ£¬µ«Èç¹uÎÒÃDz»ÐeÒª¶Ô±eÌa½øÐпØÖÆ£¬ÔÚADODBÖÐÎÒÃǾÍÓи£ÁË£¬ÎÒÃÇ¿ÉÒÔÕaÑuд£º

$strQuery = "select iNews, vcNewsTitle from tb_news_ch";
$array = &$conn->GetAll($strQuery);//×¢ÒaÕaÌoÓi¾a
$smarty->assign("News_CH", $array);
unset($array);

µ±È»£¬Õ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±¾º¯ÊýÈçÏÂ:

  1. Fields($colname):*µ»Ø×ֶεÄÖµ.
  2. RecordCount():Ëu°uº¬µÄ¼Ç¼Êý.Õa¸o¼Ç¼È*¶¨Êý¾Ý¼¯µÄ¼Ç¼×ÜÊý.
  3. GetMenu($name, [$default_str=''], [$blank1stItem=true], [$multiple_select=false], [$size=0], [$moreAttr=''])*dz£ºÃµÄÒ»

¸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

×Ö´®ºo¾Í¿ÉÒÔʹÓÃ$smarty->("TemplateVar", "GetMenuStr")À´ÔÚÄ£°aµÄ"TemplateVar" ´¦ÊaÈeÒ»¸oÏÂÀ­Áбi(»oÊǶaÏÈ¿o)
4. MoveNext():À´¿´Ò»¶Î´uÂe:

$rs = &$conn->Exceute($sql);
if($rs)
{
while($rs->EOF)
{
$array[] = array("NewsID" => $rs->fields["iNewsID"],
"NewsTitle" => csubstr($rs->fields["vcNewsTitle"]), 0, 20);

$rs->MoveNext();
}
}

Ã÷°×ÁËÂð?ºÜÏñMS ADODBÖеÄÄÇÒ»Ì×Âi!
5. MoveFirst(),MoveLast(), Move($to):Ò»ÑuµÄ,¿´º¯ÊýÃu´o¼Ò¾Í¿ÉÒÔÖªµÀËuÊÇʲôÒa˼ÁË.
6. FetchRow():*µ»ØÒ»ÐÐ,¿´´uÂe:

$rs = &$conn->Exceute($sql);
if($rs)
{
while($row = $rs->FetchRow())
{
$array[] = array("NewsID" => $row["iNewsID"],
"NewsTitle" => csubstr($row["vcNewsTitle"]), 0, 20);
}
}

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例