µ±Ç°Î»ÖãºLinux½Ì³Ì - Linux - ÍøÂçÊý¾Ý¿â5Èս̳Ì(4)

ÍøÂçÊý¾Ý¿â5Èս̳Ì(4)



        
    Ô­×÷Õß:Richard Dice


    --------------------------------------------------------------------------------

    ÍøÂçÊý¾Ý¿â½Ì³Ì£­[µÚ£´Ìì]


    Ò» ÍøÂçÊý¾Ý¿â½Ì³Ì - µÚËÄÌì
    ¶þ ePerl - PerlºÍHTMLµÄ½áºÏ
    Èý DBI - PerlµÄÊý¾Ý¿â½Ó¿Ú
    ËÄ Ç°¾° ...

    --------------------------------------------------------------------------------

    Ò»¡¢ µÚËÄÌì

    ǶÈëʽÍøÂç±à³ÌÀíÄî

    ¼¸ÄêÇ°£¬ÍøÂç±à³ÌÆðʼÓÚ¹«¹²Íø¹Ø½Ó¿Ú£¨Common Gateway Interface£©¼ò³ÆCGI¡£CGIµÄ»ù±¾¸ÅÄîÈçÏ£º

    µ±Ò»¸öÓû§·¢³öÒ»¸öCGIÇëÇóʱ£¬URL½«¼ÓÈëһЩÐÅÏ¢È÷þÎñÆ÷½«Æä°´ÕÕCGIÇëÇó½øÐд¦Àí¡£URL¼ÓÈëµÄÐÅÏ¢ÐÎʽ¿ÉÄÜÈçÏ£º
    Óû§ÇëÇóµÄCGIÒ»°ãÔÚ/cgi-bin/ ×ÓĿ¼£ºhttp://www.somewhere.com/cgi-bin/ij¸öCGI³ÌÐò
    ÍøÂç·þÎñÆ÷µÄÅäÖÿÉÄÜ»á×Ô¶¯½«Ä³Ð©ÎļþµÄÀ©Õ¹Ãûʶ±ðΪ¿ÉÒÔÖ´ÐеÄCGI³ÌÐò£ºhttp://www.erehwon.org/gosearch.py.py ͨ³£±»Àí½âΪPython³ÌÐò£¬ÕâÊÇÁíÍâÒ»ÖÖºÜÁ÷ÐеÄÍøÂç±à³ÌÓïÑÔ¡£
    ÎļþµÄÀ©Õ¹Ãû¿ÉÄÜÖ±½Ó²ÉÓÃCGI×÷ΪÀ©Õ¹Ãû£ºhttp://www.xyz.net/dosomething.cgi
    ÔÚÕâЩÇé¿öÖУ¬ÍøÂç·þÎñÆ÷½«Óû§ÇëÇ󽻸øURLÖ¸¶¨µÄ³ÌÐò½øÐд¦Àí£¬²¢ÌṩÏàÓ¦µÄÐÅÏ¢£ºÍ¨³£ÊÇ»·¾³±äÁ¿ºÍ±ê×¼ÊäÈë(STDIN)¡£
    È»ºó³ÌÐò¿ªÊ¼ÔËÐУ¬Éú³É×Ó½ø³Ì²¢Éú³ÉÏàÓ¦µÄÐÅÏ¢£¬È»ºó½«Æä·¢Ë͸ø±ê×¼Êä³ö(STDOUT)£¬Í¨³£³ÌÐò»áÉú³ÉÒ»¸ö¾¡¿ÉÄܼò¶ÌµÄHTTPÍ·ÐÅÏ¢£¬×÷ΪÆäÊä³öµÄÒ»²¿·Ö¡£
    ÍøÂç·þÎñÆ÷½«¡°²¶×½¡±µ½µÄ²¶×½Êä³öÁ÷·¢Í¨¹ýÍøÂçË͸øÓû§¡£Óû§µÄä¯ÀÀÆ÷¸ù¾ÝHTTPÍ·½«Æä½øÐз­Ò룬Æä½á¹ûͨ³£ÊÇHTMLÎı¾£¬µ«ÊÇCGI³ÌÐòÒ²¿ÉÒÔºÜÈÝÒ×µØÉú³É×Ö½ÚÁ÷×îºó½«Æ仹ԭΪJPEGͼÏó»òRealAudio½ÚÄ¿¡£
    ±ê×¼µÄ¼òµ¥C³ÌÐòÈçÏ£º

    #include <stdio.h>

    int main () {

    print(\"Hello, world!\\n\");

    }
    ÎÒ¿ÉÒÔºÜÈÝÒ׵ؽ«Æäת»¯³ÉCGI³ÌÐò£¬Ö»Ðè¼ÓÈëÒ»¸öHTTPÍ·¡£

    #include <stdio.h>

    int main () {

    print(\"Content-type: text/plain\\n\\n\");

    print(\"Hello, world!\\n\");

    }
    ÏÂÃæËùÐè×÷µÄÖ»ÊDZàÒë´úÂ룬½«±àÒëºóµÄ¶þ½øÖÆÎļþ·ÅÔÚÎÒµÄÍøÂçĿ¼ÖÐÊʵ±µÄλÖá£

    CGIÔÚ»¥ÁªÍøÊÀ½çµÄÓ¦Óúܹ㷺£¬µ«ÊǶÔËüÒ²Óкܶ಻ÂúÒâÖ®´¦¡£

    Éú³É×Ó½ø³ÌÊÇÒ»¸öÏ൱¸´ÔӵŤ×÷£¬ºÄ·ÑºÜ¶àʱ¼äºÍÄڴ棬Ðí¶à·ÃÎÊÂÊÏ൱¸ßµÄÕ¾µãµÄ¿ª·¢ÈËÔ±³£ÒòΪÓÉ´ËÔì³ÉµÄËÙ¶ÈÎÊÌⱧԹ²»ÒÑ¡£
    ÍøÂç·þÎñÆ÷°üº¬ºÜ¶àÐÅÏ¢£¬¶ø²»Ö»ÊÇ»·¾³±äÁ¿ºÍ±ê×¼ÊäÈ루STDIN£©¡£ÓÐʱºòÈç¹ûÍøÂç³ÌÐòÄܹ»·ÃÎÊÕâЩ×ÊÁϽ«»á´øÀ´Ðí¶à±ãÀû¡£
    ´«Í³µÄ±à³Ì¶ÔÓÚ»¥ÁªÍøÀ´Ëµ¶¼ÏԵùýÓÚÓ·Ö×ÅÓ´ó£¬Äã×îÐèÒªµÄÆäʵ¾ÍÊÇÒ»¸öÄÜ´úÌæÄã±àдHTMLµÄÒ»¸öÖÇÄܳÌÐò£¬ËùÒÔ£¬ÎªÊ²Ã´Òª°Ñ³ÌÐò±àµÃÏó¼ÆËã»úµÄ´úÂëÄØ£¿ÎªÊ²Ã´²»ÄÜʹËü¸üÏóHTML±¾Éí£¿
    ±àд»¥ÁªÍøÓ¦ÓóÌÐò×îÏÖ´úµÄ·½·¨²úÉúÓÚ×î½üµÄ¼¸Äê¡£ÕâЩ±à³Ì·½·¨ÆðÔ´ÓÚ»ùÓÚÓû§¶ËµÄHTML£¬»òÕß½Ð.shtml£¬Æä¸ÅÄîÇ¿´óÖ®´¦ÔÚÓÚ½«±à³Ì´úÂëǶÈëHTMLÎļþ¡£Ò»Ð©±È½ÏÁ÷ÐеÄÀý×ÓÈçÏ£º

    Active Server Pages (.aspÎļþ), ÕâÖÖ³ÌÐòÓ¦ÓÃÓÚ΢ÈíµÄIISÍøÂç·þÎñÆ÷¡£ASPÎļþ¿ÉÒÔÓü¸ÖÖ±ÈÌصĽű¾±àдÒýÇæÀýÈçVBScript, JavaScript,ºÍPerlScriptÆô¶¯¡£
    Allaire Cold Fusion,ÕâÊÇÒ»Öַdz£·½±ãµÄÉÌÓû¥ÁªÍø¿ª·¢»·¾³¡£¾¡¹ÜËü×î³õÖ»ÄÜÓÃÓÚWindows NT£¬µ«ºóÀ´ËüÒ²¿ª·¢³öÁËÊÊÓÃÓÚUNIXµÄ°æ±¾¡£
    Meta-HTML, ÕâÖÖ\"Ãâ·ÑÈí¼þ\"ÊÊÓÃÓÚUNIX ϵͳ£¬ËüÖ§³ÖODBCÒÔ¼°±¾µØ»¯µÄmSQL½Ó¿Ú£¬Ëü¿ÉÒÔÌṩÓÃÓÚNetscapeºÍApacheÍøÂç·þÎñÆ÷µÄ²å¼þÈí¼þ¡£
    ±¾ÎÄÖÐÎÒ²»¾ßÌå̸ÕâЩ¹¤¾ß£¬µ«ÎÒ´òËã̸һÏÂRalf EngelschallµÄePerl£¬ÕâÖÖÓ¦ÓóÌÐòʹÄãÄܽ«PerlÔ´´úÂëǶÈëµ½Îı¾ÎļþÖС£Ëü»¹¼¯³ÉÁËmod_perl/Apache£¬ÕâЩÊÂÏîÒÔÇ°ÎÒÃÇÐèÒªÔÚApacheµÄÉèÖÃÖÐÍê³É¡£mod_perl/ApacheµÄ¼¯³ÉÇ¿µ÷Ëٶȼ°½â¾öCGI±à³ÌÖжԷþÎñÆ÷£­ÄÚ³ÌÐò·ÃÎʵÄʧ°Ü£¬¶øePerlÔò´¦Àí±ê×¼±à³ÌÓïÑÔÔÚÉú³ÉHTMLʱµÄÓ·Ö׺ÍÂÞà¡£



    ¶þ¡¢ePerl - PerlºÍHTMLµÄ½áºÏ

    ÒªÏëÊìÁ·ÔËÓÃePerl£¬Äã±ØÐë¶ÔHTMLºÍPerl¶¼ºÜÁ˽⡣

    ¡¡

    Èç¹ûÄã¶ÔÆä²»Á˽⣬ÎÒÃÇÏÈÒÔÒ»¸ö¼òµ¥µÄHTMLΪÀý¡£

    <HTML>

    <HEAD><TITLE>A simple HTML document</TITLE></HEAD>

    <BODY>

    <P>

    This is about as simple as it gets. No big deal.

    </BODY>

    </HTML>
    ÏÖÔÚÎÒÃÇǶÈëһЩPerl´úÂë:



    <HTML>

    <HEAD><TITLE>A slightly less simple ePerl-HTML

    document</TITLE></HEAD>

    <BODY>



    <P>

    Just before a chunk of embedded Perl ...



    <HR>



    <?

    my $index;

    foreach $index ( 1 .. 10 ) {

    print \"Currently on loop index: $index\\n\";

    }

    !>



    <HR>



    <P>

    ... and now, we\"re just after the ePerl.



    </BODY>

    </HTML>
    ÆäÏÔʾ½á¹ûÊÇÏÔ¶øÒ×¼ûµÄ¡£ÎÒÔÚÕâÀïÓÃÁËÒ»¸ö¼òµ¥µÄ\"for\" Ñ­»·À´Êä³öÒ»¸öÐÅÏ¢ÏÔʾѭ»·µÄ½ø³Ì¡£ePerl Ó÷ָî·û<?¿ªÊ¼£¬Ó÷ָî·û!>½áÊø¡£ÔÚÒ»¸öePerl³ÌÐò¿éÖÐÄãÈÔÈ»¿ÉÒÔÓÃÆÕͨµÄPerlÊä³öÆÁÄ»ÐÅÏ¢¡£Ö»ÒªÄãÁ˽âPerl£¬ePerl¶ÔÄãÀ´Ëµ¾Í²»ÄÑ¡£

    ÓÃePerl½øÐÐÍøÂç±à³ÌʱµÄ×¢ÒâÊÂÏ

    ePerlÄÜ×Ô¶¯Ê¶±ðÄãµÄÍøÂçÎļþµÄÐÔÖʲ¢ÓÃÒ»¸öÊʵ±µÄHTTPÍ·¼ÓÒÔÊä³ö¡£Èç¹ûÄãµÄÎļþÊÇHTML£¬ËüµÄÊä³öÔòÊÇtext/html£¬·ñÔòËü¾Í¼òµ¥µØÓÃtext/plainÊä³ö¡£
    µ±ÐèÒªÔÚHTMLÖвåÈë±äÁ¿µÄÊýֵʱ£¬ePerl¿ÉÒÔʹÓÿì½Ý¼ü£¬ÆäÌØÊâµÄ¶¨½çÐòÁÐÊÇ<?=$±äÁ¿!>
    ÔÚ!>½áβ·Ö¸î·ûÖ®ºóÄã¿ÉÒÔ¼ÓÈë//ÒÔ·ÀÖ¹Êä³ö<? ... !> ÐС£Õâ¿ÉÒÔ±ÜÃ⽫HTMLÔ´³ÌÐòÏÔʾµ½ÍøÂçÖС£
    Äã¿ÉÒÔÓÃ#includeÉùÃ÷½«ÆäËûÎļþ°üÀ¨µ½ePerlÖС£
    ¡¡

    ÔÚÉîÈë½éÉÜePerl֮ǰ£¬ÎÒ»¹ÒªÌ¸Ò»ÏºÍperl/ApacheÓйصÄÁ½µã£º

    mod_perlÊǽ«PerlÁ¬½Óµ½ApacheÍøÂç·þÎñÆ÷µÄPerlµÄ·­ÒëÆ÷¡£ÈκÎmod_perlÔËÐеÄPerl³ÌÐòʵ¼ÊÉϲ»ÊÇËüÃÇ×Ô¼ºµÄ³ÌÐò£¬ËüÃDZ»¿´×÷ÊÇÒ»¸öÖ÷³ÌÐòµÄ×Ó³ÌÐò¡£ÕâÑù¿ÉÒÔ¼Ó¿ì³ÌÐòµÄËٶȣ¬µ«Ò²ÓпÉÄÜ´øÀ´ÎÊÌ⣺Äã¿Ï¶¨²»Ï£ÍûÔÚ²»Í¬µÄPerl½Å±¾ÖеıäÁ¿·¢ÉúÖØÃûµÄ¡°³åÍ»¡±¡£ ePerlÓÃÑϸñµÄ¹æÔò±ÜÃâÕâÀàÊÂÇéµÄ·¢Éú¡£Äã±ØÐ뽫ËùÓеıäÁ¿¶¼ÉùÃ÷Ϊmy£¬Õâ¸ö¹Ø¼ü×Ö¸æËßPerl½«±äÁ¿·ÅÔÚÒ»¸öרÓеÄÃüÃûλÖá£

    ÔÚePerlÖÐʹÓÃ#includeÉùÃ÷ʱҪ½÷É÷£¬·ñÔò»á³öÏÖÎÊÌâ¡£¿´Ò»ÏÂÏÂÃæµÄÀý×Ó£¬Ò»¸öСePerlÎļþTT>time.iphtml:



    print scalar localtime;

    //

    ÎÒ½«Ëü°üÀ¨µ½Ò»¸ö´óµÄePerlÎļþ .iphtmlÖÐ:

    <HTML>

    <HEAD><TITLE>The Current Time</TITLE></HEAD>

    <BODY>



    <P>

    The current time is: <B>

    #include time.iphtml

    </B>



    </BODY>

    </HTML>

    (ÎļþµÄÀ©Õ¹Ãû.iphtmlÊÇePerl±à³ÌÎļþµÄËõд£¬Ëü´ú±íInternally Parsed HTML)

    mod_perlÓÃÁËÒ»Ïî¼¼ÇɼӿìPerl³ÌÐòÔÚApacheÖÐÔËÐеÄËٶȡ£ÕâÏî¼¼ÇɾÍÊǽ«±àÒëºóµÄPerl·ÅÔÚ¸ßËÙ»º´æÖС£Perl³ÌÐòÔËÐÐÇ°ÐèÒªÁ½¸ö²½Ö裺½âÊͺͱàÒë¡£ mod_perlÄÜ \"¼ÇÒä\" ½âÊͺͱàÒë½×¶ÎµÄ½á¹û£¬ËùÒÔµ±ÒÔºó»¹ÐèÔËÐиÃPerl³ÌÐòʱ£¬mod_perl²»ÐèÒªÔÙÖ´ÐгÌÐòµÄ½âÊͺͱàÒë¹ý³Ì£¬¶øÖ±½Ó´Ó¸ßËÙ»º´æÖе÷ÓÃÉϴνâÊͺͱàÒëµÄ½á¹û¡£µ«ÊÇÈç¹ûÎļþtime.iphtml±»¸Ä±äÁ˵Ļ°£¬Ôòmod_perlÔËÐиóÌÐòʱ¾Í»á³ö´í£¬ÒòΪËü²»ÄÜʶ±ð¶ÔÎļþµÄ¸Ä±ä¡£


    Èý¡¢ DBI - PerlµÄÊý¾Ý¿â½Ó¿Ú

    DBIÊÇÒ»¸ö·Ç³£ÊµÓõÄPerlÄ£¿é¡£ËüÊÇPerlºÍSQLÇý¶¯µÄÊý¾Ý¿âÖ®¼äµÄ½Ó¿Ú¡£ËüʹÄãÄÜÖ´ÐÐÊý¾Ý¿âµÄ¹ÜÀí¹¦ÄÜ£¬°üÀ¨Perl programsÒÔ¼°´ÓÄãµÄPerlÔ´´úÂë·¢³öSQLÖ¸Áÿһ¸öÊý¾Ý¿â¶¼ÓÐÒ»¸ö½«Í¨ÓÃDBI½Ó¿ÚÁ¬½ÓÌض¨µÄÊý¾Ý¿â·þÎñÆ÷µÄÊý¾Ý¿âÇý¶¯Æ÷£¨DataBase Driver £­DBD£©¡£ÕâÑùÒÔÀ´£¬ÓÃDBI±àдµÄPerl³ÌÐò¾ßÓкܺõÄÒÆÖ²ÐÔ¡£Äã¸Ä±äËùÓõÄÊý¾Ý¿â·þÎñÆ÷ʱ£¬Ö»ÐèÉÔ΢¸Ä±ä¼¸ÌõPerl´úÂë¼´¿É¡£

    ÒªÓ¦ÓÃDBIµÄÉñÆ湦ÄÜ£¬ÄãÖ»ÐèÔÚPerl³ÌÐò¿ªÊ¼´¦¼ÓÈëÕâÑùÒ»ÐУº

    use DBI;
    Èç¹ûÄã°´ÕÕÎÒ×òÌìµÄ¿Î³ÌÉèÖÃÁËmod_perl/ApacheµÄ×éºÏ£¬ÄÇôÄãʵ¼ÊÉϲ»ÐèÒª¼ÓÈëÕâÐдúÂë¡£ÎÒ¸øÄãÌṩµÄstart-up.perlÎļþÖÐΪÄãÌṩÁËÈÃÿ¸öPerl/ePerl³ÌÐò¶¼Í¨¹ýmod_perlÔËÐеŦÄÜ¡£

    ʵ¼ÊµÄDBI Perl±à³ÌÓкܶàÖظ´ºÍÂß¼­ÐÔµÄÄÚÈÝ£¬ËùÒÔ½âÊÍÆðÀ´ºÜÈÝÒס£

    Ê×ÏÈ£¬ÄãÉú³ÉÒ»¸ö¶ÔÏó×÷Ϊ¡°Êý¾Ý¿âµÄ´¦ÀíÆ÷¡±¡£¸Ä¶ÔÏóʹÄãÄÜÒýÓÃËùÓÐδÀ´¿ÉÄÜ·¢³öµÄSQL²éѯ£¬ÒòΪËü¶¨ÒåÁËÄãµÄÊý¾Ý¿â¡£


    $dbh = DBI->connect(\"DBI:mysql:test:localhost\", \"\",\"\")
    or die $DBI::errstr;
    DBI->connectËùÓõÄ3¸ö²ÎÊýÊÇ$database£¨Êý¾Ý¿â£©, $username£¨Óû§Ãû£©,ºÍd $password£¨¿ÚÁ¡£ÕâÀïÎÒÃÇʹÓÃ×òÌ콨Á¢µÄÒ»¸öÊÔÑéÊý¾Ý¿â×÷ΪÀý×Ó£¬ÎÒÃÇÎÞÐèÖ¸¶¨Óû§ÃûºÍ¿ÚÁÄã¿ÉÒÔʹÓÃ×Ö·û´®Á¿DBI:mysql:test:localhost×÷ΪÄãµÄ$database²ÎÊý¡£µ«ÊÇÕâÖ»ÊÇÔÚ±¾ÀýÖС£Èç¹ûÄãÓñðµÄÊý¾Ý¿â×÷±ðµÄÊÂÇ飬ÄãÐèÒª²Î¿¼DBIºÍDBDÎÄÏ×°ïÖúÄãÈ·¶¨ÐµÄ$database×Ö·û´®¡£

    ÏÂÃ棬±àдһЩSQL´úÂ룬²¢½«Æä·ÅÈë±äÁ¿¡£ÀýÈ磬ÔÚÎÒ×òÌìµÄÀý×ÓÖУº

    $SQL = <<\"EOT\"; select title, released from albums
    where artist=\"Genesis\" order by released EOT
    Õâ¸ö±äÁ¿ÊÇÓû§¶Ë¹â±ê²éѯ£¨cursor£©µÄºËÐÄ¡£¹â±ê²éѯ £¨cursor£©ÊÇÒ»ÖÖÏȽøµÄSQL²éѯ·½·¨£¬ËüÖ´ÐÐÖðÐвéѯ¹¦ÄÜ¡£¸Ã²éѯ¹¦ÄÜʵ¼ÊÉÏÔÚͬʱȫ²¿Ö´ÐУ¬µ«ÎÒÃǵÄPerl²éѯֻÄÜÒ»ÐÐÒ»ÐеػñµÃ²éѯ½á¹û£¬ËùÒÔËü¸Ð¾õÉÏÏóÊÇÕë¶ÔÓ¦ÓóÌÐòµÄ¹â±ê¡£Óû§¶Ë¹â±ê²éѯµÄÓï¾ä¼°Ö´ÐдúÂëÈçÏ£º

    $cursor = $dbh->prepare($SQL);

    $cursor->execute;
    ÏÖÔÚÎÒÃÇÖðÐнøÐвéѯ:

    while ( @columns = $cursor->fetchrow ) {

    print ( ( map { \"[$_]\" } @columns ) , \"\\n\");

    }
    ÕâÐÐPerl´úÂëÓÃÓÚ´òÓ¡³öÁÐÐòÁÐÖеÄÿһÌõÊý¾Ý£­ÆäÊýÖµÀûÓà $cursor-> fetchrow·½·¨´Ó$cursorÐÐÖÐÌáÈ¡³öÀ´¡£ÆäÊýÖµÓÃ[ ]°üΧ¡£ºÜÏÔÈ»£¬ÎÒ¿ÉÒÔ½«ÈκÎÄÚÈÝ·ÅÔÚwhileÑ­»·ÄÚ£¬¶ø²»Ö»ÊÇ´òÓ¡Óï¾ä¡£

    ×îºó£¬ÊµÏÖϵͳ×ÊÔ´µÄ»ØÊպͶϿªÁ¬½Ó¡£ÎÒÃǹرչâ±ê²éѯºÍÊý¾Ý¿â´¦ÀíÆ÷¡£

    $cursor->finish;

    $dbh->disconnect;
    Èç¹ûij¸öÄãÏëÖ´ÐеÄSQÖ¸Áî²»ÊÇselectÓï¾ä£¬Äã²»ÐèҪʹÓÃwhile ( $cursor->fetchrow ) { ... } Ñ­»·£¬ÒòΪÄãʵ¼Ê²¢²»ÐèÒª·¢²¼»áÈκÎÐÅÏ¢£¬Äã²»ÐèҪѭ»·²éѯ¸÷ÐС£

    ¼ÙÈçÔÚ×òÌìµÄÀý×ÓÖУ¬ÎÒûÓдÓalbumÊý¾Ý¿âÖÐɾ³ýmy GenesisÐÅÏ¢£¬ÎÒ½«ÀûÓýñÌìËùѧµÄ·½·¨½«Æä±ä³ÉÒ»¸ö¿ÉÒÔÓ¦ÓÃÓÚ»¥ÁªÍøµÄePerl³ÌÐò¡£


    use DBI; # ¼ÙÈçÄãûÓÐstartup.perlÎļþÔòÐèÒª¼ÙÈç¸ÃÐдúÂë



    my $dbh = DBI->connect(\"DBI:mysql:test:localhost\", \"\",\"\")

    or die $DBI::errstr;

    my $SQL = <<\"EOT\";

    select title, released

    from albums

    where artist = \"Genesis\"

    order by released

    EOT



    my $cursor = $dbh->prepare($SQL);

    $cursor->execute;

    //

    <HTML>

    <HEAD><TITLE>ePerl/DBI/HTML Integration

    Example</TITLE></HEAD>

    <BODY>


    <P>

    ÓйØGenesis albumsµÄÊý¾Ý¿â³ÌÐò½á¹ûΪ ...


    <HR>


    <TABLE BORDER>

    <TR><TH COLSPAN=2>Albums by Genesis</TH></TR>

    <TR><TH>Title</TH><TH>Release

    Date</TH></TR>


    my @columns;

    while ( @columns = $cursor->fetchrow ) {

    print ( \"<TR>\",( map { \"<TD>$_</TD>\" }

    @columns ) , \"</TR>\\n\");

    }

    /

    </TABLE>



    <HR>



    <P>

    ... and that\"s it!



    </BODY>

    </HTML>


    $cursor->finish;

    $dbh->disconnect;

    //
    Äã¿ÉÒԲ鿴¸Ã³ÌÐòÖ´ÐеĽá¹û¡£

    Albums by Genesis
    Title Release Date
    Selling England By The Pound 1973-01-01
    Trespass 1974-01-01
    A Trick of the Tale 1976-01-01
    Wind & Wuthering 1976-01-01
    Duke 1980-01-01
    We Can\"t Dance 1990-01-01

    ËÄ¡¢ Ç°¾° ..

    ÎÒÃÇÒѾ­Ñ§Ï°ÁËÍøÂçÊý¾Ý¿â±à³ÌµÄ»ù±¾ÖªÊ¶£¬ÔÚµÚ5ÌìµÄ¿Î³ÌÖУ¬ÎÒÃǽ«±àдһ¸öϵͳÑÝʾ±àдÍøÂçÊý¾Ý¿â½«Óöµ½µÄ¸÷ÖÖÇé¿ö¡£

    ÔÚÉú³É¸ÃÊý¾Ý¿â֮ǰ»¹ÓÐһЩϸ½ÚÎÊÌâÐèÒªÑо¿¡£¶øÇÒÎÒÃÇÒ²²»ÄÜÍü¼ÇÎÒÃÇÏòÊý¾Ý¿â´æÈ¡ÐÅÏ¢µÄ»ù±¾Í¾¾¶£ºHTML±íµ¥¡£ÎÒ½«Óõ½ÁíÍâÒ»¸öÓÐÓõÄPerl Ä£¿é£¬CGI.pm¡£
    ·¢²¼ÈË:netbull À´×Ô:LinuxÊý¾ÝÓ¦ÓÃÖ¸ÄÏ