PHP ÇÏ¿ìÅõ Al Dev (Alavoor Vasudevan) alavoor@yahoo.com v8.0, 26 Sep 2000 À±±¤È£(KwangHo, Yun), airplanez@kldp.org PHP-HOWTO_kr.sgml, v0.01 2000/11/07 15:50 À̹®¼­´Â ¾î¶»°Ô PHP ÇÁ·Î±×·¥À» ¸¸µå´ÂÁö¿Í Windows 95 GUI ¾îÇø®ÄÉÀ̼ÇÀ» ÈǸ¢ÇÑ PHP + HTML + DHTML + XML + Java applets + Javascript ·Î ¹Ù²Ù´Â °ÍÀ» ¼³¸íÇÒ°ÍÀÌ´Ù. À̹®¼­¿¡ ÀÖ´Â Á¤º¸´Â PHP°¡ Æ÷Æà µÇ¾úÀÖ´Â Linux, Windows 95/NT, OS/2, Unix °è¿­ÀÇ Solaris, HPUX, AIX, SCO, Sinix, BSD, µîµîÀÇ ¿î¿µÃ¼°è¿¡ Àû¿ëµÈ´Ù. ______________________________________________________________________ ¸ñÂ÷ 1. ¼Ò°³ 2. PHP ³»·Á¹Þ±âAID CDATA PHP Download(LABEL)LABEL 2.1 Microsoft Windows 95/98/NT/2000¿¡ PHP ¼³Ä¡AID CDATA PHP Installation(LABEL)LABEL 2.2 À¯´Ð½ºµé°ú ´Ù¸¥ Ç÷¿Æû¿¡¼­ PHP ¼³Ä¡AID CDATA PHP Installation(LABEL)LABEL 3. PHP Æ©Å丮¾ó AID CDATA PHP Tutorial(LABEL)LABEL 4. PHPÀ» À§ÇÑ IDE(ÅëÇÕȯ°æ) µµ±¸ AID CDATA PHP IDE(LABEL)LABEL 5. ³î¶ó¿î !!! PHP¸¦ À§ÇÑ ctags ! AID CDATA ptags(LABEL)LABEL 6. PHP µð¹ö±ë AID CDATA debugphp(LABEL)LABEL 7. PHPÀÇ Á¦ÇÑ 8. °ü°èÀÖ´Â URLµé 9. À̹®¼­ÀÇ ´Ù¸¥ Æ÷¸ä 10. ÀúÀÛ±Ç 11. ºÎ·Ï A Database Wrapper ¿¹Á¦ AID CDATA Appendix A(LABEL)LABEL 12. ºÎ·Ï B SQL abstraction Example AID CDATA Appendix B(LABEL)LABEL 13. ºÎ·Ï C PostgreSQL large object ¿¹Á¦ AID CDATA Appendix C(LABEL)LABEL 14. ºÎ·Ï D »ç¿ëÀÚ ÀÎÁõ ¿¹Á¦ AID CDATA Appendix D(LABEL)LABEL 15. ºÎ·Ï E ³×Æ®¿öÅ© °ü¸® ¿¹Á¦ AID CDATA Appendix E(LABEL)LABEL 16. ºÎ·Ï F PostgreSQL Database Wrapper ¿¹Á¦ AID CDATA Appendix F(LABEL)LABEL 17. ºÎ·Ï G Microsoft SQL Server DB Wrapper ¿¹Á¦ AID CDATA mssql G(LABEL)LABEL 18. ºÎ·Ï H Sybase SQL Server DB Wrapper ¿¹Á¦ AID CDATA sybase H(LABEL)LABEL 19. ºÎ·Ï I phpDB.inc ¿¹Á¦ AID CDATA phpdb I(LABEL)LABEL 20. ºÎ·Ï J phpDBTest.php3 ¿¹Á¦ AID CDATA phpDBTest(LABEL)LABEL ______________________________________________________________________ 1. ¼Ò°³ PHP ´Â 'Hypertext Pre-Processor'¸¦ ÀǹÌÇÏ°í ¼­¹ö»çÀ̵å(server side) HTML ½ºÅ©¸³ÆÃ/ÇÁ·Î±×·¡¹Ö ¾ð¾îÀÌ´Ù. PHP´Â µ¿ÀûÀÎ À¥ÆäÀÌÁö¸¦ ¸¸µé¼ö ÀÖ°ÔÇØÁØ´Ù. PHP°¡ »ç¿ëµÈ À¥ÆäÀÌÁö´Â ÀϹÝÀûÀÎ HTML ó·³ Ãë±ÞµÇ¸ç Æò¹üÇÑ HTML ÆäÀÌÁöó·³ »ý¼º°ú ¼öÁ¤À» ÇÒ¼ö ÀÖ´Ù. ¸¹Àº ȸ»çµéÀÌ PHP´Â "Á߿亸¾È°ú ¾ö°ÝÇÑ ºñ¹Ð"À» À¯ÁöÇÒ¼ö ÀÖ´Â ÄÄÇ»ÅÍ ¾ð¾î¶ó°í ¸»ÇÏÁö¸¸, ±×·¯³ª Áö±ÝÀº À߾˷ÁÁö°í ¸¹ÀÌ ¾²ÀÌ´Â À¥, ÀÎÅͳÝ, ÀüÀÚ»ó°Å·¡¿Í B2B(business-to-business) ÇÁ·ÎÁ§Æ®À» À§ÇÑ ½ºÅ©¸³Æ® ¾ð¾î°¡ µÇ¾ú´Ù. ±×·³¿¡µµ ºÒ±¸ÇÏ°í ¿äÁò ¸¹Àº °æÀïȸ»çµéÀÌ PHP¾ð¾î¸¦ º¸¾È¿¡ ´ëÇؼ­ ¾ÈÀüÇÏÁö¾Ê´Ù°í ÇÑ´Ù(°æÀïÀÚµé).(¿ªÁÖ:¹ø¿ªÀÌ ¿µ ÀÌ»óÇϳ×..) PHP´Â Àü¼¼°è¿¡ µ¹Ç³À» ÀÏÀ¸Å³ °ÍÀ̸ç IT¾÷°è¸¦ ³î¶ø°Ô Á¡À¯ÇÏ°Ô µÉ°ÍÀÌ´Ù!! PHPÀÇ ÆÄ¿ö´Â Å©·Î½º-Ç÷§Æû ÀÌ°í ¾î´À°÷¿¡¼­µµ ½ÇÇàµÈ´Ù!! PHP´Â ¸®´ª½º, À©µµ 95/98/NT, À©µµ 2000, ¼Ö¶ó¸®½º, HPUX¿Í ¸ðµç À¯´Ð½º °è¿­¿¡¼­ ½ÇÇàµÈ´Ù. PHP´Â ÇѹøÀÛ¼º µÇ¸é ¾îµð¼­³ª ½ÇÇàµÈ´Ù. PHP´Â ¾ÆÆÄÄ¡, ¸¶ÀÌÅ©·Î¼ÒÇÁÆ® IIS µîµîÀÇ ¸¹Àº À¥¼­¹ö¿¡¼­ ½ÇÇàµÈ´Ù. PHP´Â ÀÚ¹Ùº¸´Ù 5¿¡¼­ 20¹è±îÁö ºü¸£´Ù!! PHP´Â »ç¿ëÇϴµ¥ ¹«Ã´½±°í, ¸Å¿ì º¹ÀâÇÑ À¥/ÀüÀÚ»ó°Å·¡ ¾îÇø®ÄÉÀ̼ÇÀ» ¸Å¿ì ºü¸£°í ªÀº ½Ã°£¿¡ °³¹ßÇÒ¼ö ÀÖ´Ù. PHP´Â °´Ã¼ÁöÇâÀûÀΠƯ¡°ú ÀÚ¹Ù, C++, PERL°ú "C"·Î ºÎÅÍ ÈǸ¢ÇÑ Æ¯Â¡À» °¡Á®¿Ô´Ù. PHP¾ð¾î´Â ÀÚ¹Ù, C++, PERL°ú CÀÇ ÈǸ¢ÇÑ Æ¯Â¡ÀÇ °áÇÕüÀÌ´Ù. PHP´Â ¸ðµç ½ºÅ©¸³Æ®/ÇÁ·Î±×·¥ ¾ð¾îÀÇ ÁøÁ¤ÇÑ º¸¼®ÀÌ¸ç °ð Àü¼¼°è ÇÁ·Î±×·¡¸ÓÀÇ "¸ÞÄ«"°¡ µÉ°ÍÀÌ´Ù!! PHP´Â À©µµ 95/NT ¿Í ¸ðµç À¯´Ð½º¿¡¼­ ½ÇÇàµÇ±â ¶§¹®¿¡ °Å´ëÇÑ »ç¿ëÀÚÃþ°ú ¸¹Àº °³¹ßÀÚÃþÀ» °¡Áø´Ù. PHP´Â º¸´Ù ºü¸£°Ô ½ÇÇàµÇµµ·Ï Á¨¿ÉƼ¸¶ÀÌÀú(Zend Optimizer)¸¦ »ç¿ëÇÏ¿© ÄÄÆÄÀÏ°ú ÃÖÀûÈ­(optimized)½Ãų¼ö ÀÖ´Ù. Á¨¿ÉƼ¸¶ÀÌÀú(Zend Optimizer)´Â PHP ¹öÀü 4.0¿¡¼­ ºÎÅÍ PHP¿¡ ÅëÇյǾú´Ù. ´ç½ÅÀº ÀüÀÚ»ó°Å·¡(e-commerce) ÇÁ·ÎÁ§Æ®¸¦ Çϴµ¥ º¸Åë PHP (70% ÄÚµå) + HTML/DHTML/XML (25% ÄÚµå) + Javascript (5% ÄÚµå Ŭ¶óÀ̾ðÆ® Ãø) ÀÇ Á¶ÇÕÀ» »ç¿ëÇÒ°ÍÀÌ´Ù. 2. PHP ³»·Á¹Þ±â o PHP ¸ÞÀÎ »çÀÌÆ® o PHP ¸®¼Ò½º o PHP ÄÚµå º¯È¯ - 2.1. Microsoft Windows 95/98/NT/2000¿¡ PHP ¼³Ä¡ PHP´Â Microsoft Windows Ç÷¿Æû¿¡¼­ ¸Å¿ì ÀαâÀÖ°í ³î¶ø°Ôµµ MS ÀÇ ASP ½ºÆ®¸³Æ® ¾ð¾îº¸´Ù ´õ ÀαâÀÖ´Ù!! PHPÀÇ °¡ÀåÅ« ÀåÁ¡Àº MS À©µµ¿Í ¸®´ª½º, À¯´Ð½º¿¡¼­ °³¹ßÇÒ¼ö ÀÖ°í ¹Ý´ë·Î »ç¿ëÇÒ¼öµµ ÀÖ´Ù´Â °ÍÀÌ´Ù!! MS À©µµ 98/NT/2000 ¿¡¼­ PHPÀÇ ¼ö¿ä°¡ ¸¹±â ¶§¹®¿¡ ½ÇÇà°¡´ÉÇÑ ¼³Ä¡ÇÁ·Î±×·¥ÀÌ ÁغñµÇ¾î ÀÖ´Ù. ´ÜÁö ½ÇÇàÈ­ÀÏÀ» ´õºíŬ¸¯ ÇÏ´Â °Í¸¸À¸·Î 2ºÐ¸¸¿¡ PHP¼³Ä¡°¡ ÀÚµ¿À¸·Î ÀÌ·ç¾îÁø´Ù. ½ÇÇà°¡´ÉÇÑ ¼³Ä¡È­ÀÏÀ» ´Ù¿î·ÎµåÇ϶ó. o MS WindowsÀÇ PHP ¼³Ä¡ ÇÁ·Î±×·¥ o ¸¹Àº À©µµ Ç÷¿ÆûÀÇ PHP Á¤º¸ 2.2. À¯´Ð½ºµé°ú ´Ù¸¥ Ç÷¿Æû¿¡¼­ PHP ¼³Ä¡ PHP ¸ÞÀλçÀÌÆ® ³ª ´Ù¿î·ÎµåÇÑ ÆÐÅ°ÁöÀÇ ¼³Ä¡ÆÄÀÏ ¿¡¼­ ¼³Ä¡°¡À̵å¿Í Áö½Ã¸¦ º¸¶ó. 3. PHP Æ©Å丮¾ó ¿©±â¿¡¼­´Â ´ç½ÅÀÇ ¼­¹ö°¡ PHP °¡ °¡´ÉÇÏ°í .php3·Î ³¡³ª´Â ¸ðµç È­ÀÏÀÌ PHP¿¡ ÀÇÇØ ½ÇÇàµÈ´Ù°í °¡Á¤ÇÑ´Ù. ù¹ø° PHP°¡ °¡´ÉÇÑ ÆäÀÌÁö: ´ÙÀ½ÀÇ ¶óÀÎÀ» ³Ö¾î¼­ hello.php3¶õ È­ÀÏÀ» ¸¸µé¾î¶ó: ______________________________________________________________________ < head>< title >PHP Test< /title >< /head > < body> "; ?> < /body>< /html> ______________________________________________________________________ CGI ½ºÅ©¸³Æ® ó·³ º¸ÀÌÁö ¾ÊÀ»°ÍÀÌ´Ù. Ưº°ÇÑ Å±׸¦ °¡Áö°í ÀÖ´Â º¸Åë HTML ó·³ »ý°¢Ç϶ó. ¸¸¾à ÀÌ°ÍÀ» ½ÇÇàÇߴµ¥ ¾Æ¹«·± °á°úµµ ³ªÅ¸³ªÁö ¾ÊÀ¸¸é, PHP°¡ ½ÇÇàµÇÁö ¾ÊÀº °ÍÀÌ´Ù. ´ç½ÅÀÇ °ü¸®ÀÚ¿¡°Ô ½ÇÇàµÇ°Ô ÇØ´Þ°í ¿äûÇ϶ó. À̹ø ¿¬½À¿¡¼­´Â PHPÀÇ Æ¯º°ÇÑ Å±׸¦ º¸¿©ÁÖ±â À§ÇÑ°ÍÀÌ ¸ñÀûÀÌ´Ù. À̹ø ¿¬½À¿¡¼­ ¿ì¸®´Â PHP ű×ÀÇ ½ÃÀÛÀ» ¾Ë¸®´Â < ?php¸¦ »ç¿ëÇÏ¿´´Ù. ±×¸®°í PHP ¹®ÀåÀ» ³Ö°í ? > ű׸¦ ³¡¿¡ ³Ö¾ú´Ù. ´ç½ÅÀº ´ç½ÅÀÌ HTML È­ÀÏÀÇ ¿øÇÏ´Â °÷¿¡ ÀÌ·¸°Ô ÇÔÀ¸·Î¼­ PHP ¸ðµå¸¦ ½ÃÀÛÇÏ°í ³¡³¾¼ö ÀÖ´Ù. ¿ì¸®´Â ÆäÀÌÁö¸¦ º¸´Â »ç¶÷ÀÌ ¾î¶² ºê¶ó¿ìÀú¸¦ »ç¿ëÇÏ´ÂÁö °Ë»çÇغ¼°ÍÀÌ´Ù. ±×·¸°Ô ÇϱâÀ§ÇØ ¿ì¸®´Â ºê¶ó¿ìÀú°¡ º¸³»¿Â ¿äû¿¡ ´ëÇÑ ºÎºÐÀ» üũÇÑ´Ù. ÀÌ Á¤º¸´Â º¯¼ö¿¡ ÀúÀåµÈ´Ù. º¯¼ö´Â ¾ðÁ¦³ª ´Þ·¯»çÀÎ($)À¸·Î ½ÃÀÛÇÑ´Ù. ¿ì¸®°¡ °ü½ÉÀ» °¡Áö´Â º¯¼ö´Â $HTTP_USER_AGENT ÀÌ´Ù. ÀÌ°ÍÀ» º¸¿©ÁÖ±â À§Çؼ­ ¿ì¸®´Â ´ÙÀ½°ú °°ÀÌ ÇÒ¼ö ÀÖ´Ù: ______________________________________________________________________ ______________________________________________________________________ Áö±Ý ´ç½ÅÀÌ ÀÌ ÆäÀÌÁö¸¦ º¸±â À§ÇØ »ç¿ëÇÏ´Â ºê¶ó¿ìÀú¿¡¼­´Â, ÀÌ·¸°Ô ³ª¿Â´Ù: Mozilla/4.0 (compatible; MSIE 4.01; Windows 98) ÀÚ½ÅÀÇ À¥¼­¹ö¿¡ ÀÇÇØ ÀÚµ¿À¸·Î ¼³Á¤µÇ´Â ¸¹Àº ´Ù¸¥ º¯¼öµéÀÌ ÀÖ´Ù. ´ÙÀ½°ú °°Àº È­ÀÏÀ» ¸¸µêÀ¸·Î¼­ ¿ÏÀüÇÑ º¯¼öÀÇ ¸®½ºÆ®¸¦ ¾òÀ»¼ö ÀÖ´Ù: ______________________________________________________________________ ______________________________________________________________________ ºê¶ó¿ìÀú·Î ÀÌÈ­ÀÏÀ» ÀоîµéÀ̸é ÀÚ½ÅÇѵ¥ °¡¿ëÇÑ ¸ðµç º¯¼öÀÇ ¸®½ºÆ®¸¦ È­¸é°¡µæ ÇÑ Á¤º¸¿Í °°ÀÌ º¼¼ö ÀÖÀ»°ÍÀÌ´Ù. PHP ű׾ȿ¡ ¿©·¯°³ÀÇ PHP ¹®ÀåÀ» Áý¾î³ÖÀ»¼ö ÀÖÀ¸¸ç ÇϳªÀÌ»óÀÇ echo ¹®À» °¡Áö´Â ÄÚµåºí·°À» ¸¸µé¼ö ÀÖ´Ù. ______________________________________________________________________ "; } ?> ______________________________________________________________________ ¿©±â¿¡¼­´Â PHP ºí·°ÀÇ Áß°£ÀÏÁö¶ó°í PHP¸ðµå¸¦ ¹þ¾î³ª´Â ¹æ¹ýÀ» º¸¿©ÁÙ°ÍÀÌ´Ù: ______________________________________________________________________ < center>< b>You are using Internet Explorer< /b>< /center> < center>< b>You are not using Internet Explorer< /b>< /center> ______________________________________________________________________ PHPÀÇ echo ¹®À» »ç¿ëÇÏ´Â ´ë½Å PHP ¸ðµå¸¦ ¹þ¾î³ª¼­ Á÷Á¢ HTML À» ³ÖÀ»¼ö ÀÖ´Ù. ¿©±â¼­ ¸»ÇÏ·Á°í ÇÏ´Â Áß¿äÇÏ°í °­·ÂÇÑ Á¡Àº ³í¸®ÀûÀÎ È帧ÀÌ ±úÁöÁö ¾Ê°í ³²¾Æ ÀÖ´Ù´Â °ÍÀÌ´Ù. ´ÜÁö HTML ºí·°µéÀº °á±¹ º¸´Â »ç¶÷¿¡°Ô¸¸ º¸³»Áö°Ô µÇ´Â°ÍÀÌ´Ù. ½ºÅ©¸³Æ®¸¦ ½ÇÇà½ÃÅ°¸é °á°ú´Â ´ÙÀ½°ú °°´Ù : You are using Internet Explorer Æû ´Ù·ç±â PHPÀÇ °¡Àå À¯¿ëÇÑ ±â´ÉÁß Çϳª°¡ HTML Æû(form)À» ´Ù·ç´Â ¹æ¹ýÀÌ´Ù. ±×°ÍÀ» ÀÌÇØÇÏ´Â Áß¿äÇÑ ±âº»ÀûÀÎ °³³äÀº Æû¿¡ ³ª¿Â ¸ðµç ¿ä¼ÒµéÀÌ ÀÚµ¿ÀûÀ¸·Î Æû¿¡ ÀÖ´Â À̸§°ú °°Àº º¯¼ö·Î ÀÚµ¿ÀûÀ¸·Î ¹Ù²î¾î ºÒ·ÁÁø(target) °÷¿¡¼­ »ç¿ë µÈ´Ù´Â °ÍÀÌ´Ù. º¹ÀâÇÏ°Ô µé¸±°ÍÀÌ´Ù. ±×·¡¼­ ¿©±â °£´ÜÇÑ ¿¹Á¦°¡ ÀÖ´Ù. ´ÙÀ½°ú °°Àº ÆûÀ» °¡Áö´Â ÆäÀÌÁö°¡ ÀÖ´Ù°í °¡Á¤Ç϶ó : ______________________________________________________________________
Your name: You age: < /form> ______________________________________________________________________ ¿©±â¿¡ ÀÖ´Â Æû¿¡´Â ¾î¶°ÇÑ Æ¯º°ÇÑ °Íµµ¾ø´Ù. ¾î¶² Ưº°ÇÑ Å±׵µ ¾ø´Â ´ÜÁö HTML Æû¿¡ ºÒ°ú ÇÏ´Ù. »ç¿ëÀÚ°¡ ÆûÀ» ÀÔ·ÂÇÏ°í Àü¼Û¹öÆ°À» ´©¸®¸é action.php3°¡ ºÒ·ÁÁø´Ù. ºÒ·ÁÁø È­ÀÏ¿¡´Â ´ÙÀ½°ú °°Àº °ÍÀÌ µé¾îÀÖÀ»°ÍÀÌ´Ù: ______________________________________________________________________ Hi . You are years old. ______________________________________________________________________ ³î¶ø°Ôµµ $name°ú $age º¯¼ö´Â PHP¿¡ ÀÇÇØ ÀÚµ¿À¸·Î Á¤ÇØÁø´Ù!! 4. PHPÀ» À§ÇÑ IDE(ÅëÇÕȯ°æ) µµ±¸ ¸¹Àº HTML ¿¡µðÅ͵éÀº PHP¸¦ Áö¿øÇÑ´Ù : o SoyalÀÇ ÈǸ¢ÇÑ PHP ¿¡µðÅÍ o Blue Fish o Coffee cup o µå¸²À§¹ö(Dreamweaver) o Amaya o Homesite o Hotdog o Zend Optimizers(Àü¿ÉƼ¸¶ÀÌÁ®) o Zend Compilers(ÀüÄÄÆÄÀÏ·¯) o MS Windows Ç÷¿Æû¿ëÀÇ ¸¹Àº PHP Á¤º¸ °¡±î¿î ½ÃÀÏ¿¡ ¸ðµç HTML ¿¡µðÅÍ¿Í XML ¿¡µðÅÍ°¡ "ºü¸¥ ¾îÇø®ÄÉÀÌ¼Ç °³¹ß" µµ±¸·Î PHP¸¦ Áö¿øÇÒ°ÍÀÌ´Ù. . 5. ³î¶ó¿î !!! PHP¸¦ À§ÇÑ ctags ! ÀÌ Å±׵éÀº »ó´çÈ÷ Áß¿äÇÏ°í vi, emacs, CRiSP, NEdit µî°ú °°Àº ¿¡µðÅÍ·Î ¼Ò½ºÄڵ带 Ž»ö(°Ë»ö)Çϴµ¥ ¾²¿©Áø´Ù. ¸¸¾à C, C++ ¶Ç´Â ÀÚ¹Ù·Î ÇÁ·Î±×·¥ÇÑ °ÍÀ» °¡Áö°í ÀÖ´Ù¸é ű׸¦ »ý¼ºÇϱâ À§ÇØ ctags ÇÁ·Î±×·¥À» »ç¿ëÇÒ¼ö ÀÖÀ»°ÍÀÌ´Ù. ¿Â¶óÀÎ ¸Þ´º¾ó ÆäÀÌÁö(online manual page)¸¦ º¸±âÀ§Çؼ­´Â ¸®´ª½º/À¯´Ð½º bash prompt ¿¡¼­ 'man ctags'¸¦ Ä¡¸é µÈ´Ù. PHP¸¦ À§ÇÑ ptags ÇÁ·Î±×·¥Àº ´ÙÀ½¿¡ ÀÖ´Ù. ±×°ÍÀ» »ç¿ëÇϸé PHP ¼Ò½ºÄڵ带 À§ÇÑ Å±׸¦ »ý¼ºÇÒ¼ö ÀÖ´Ù. ptags¸¦ »ç¿ëÇÏ¸é ´ç½ÅÀÇ »ý»ê¼ºÀº 3¿¡¼­ 4¹è±î·® Çâ»óµÉ°ÍÀÌ´Ù. ¶ÇÇÑ ¿¡ ÀÖ´Â PHP, C, C++¸¦ À§ÇÑ Vim Ä÷¯ ÅؽºÆ® ¿¡µðÅ͸¦ ÂüÁ¶Ç϶ó. ______________________________________________________________________ // ptags.cpp·Î ÀÌÈ­ÀÏÀ» ÀúÀåÇÏ°í // g++ -o ptags ptags.cpp ·Î ÄÄÆÄÀÏÇ϶ó. //***************************************************************** // GNU/GPL ÀúÀÛ±ÇÀ» µû¸¥´Ù. Ãß°¡·Î º¹»ç¸¦ ÇϰԵǸé ÀúÀÚÀÇ À̸§, // À̸ÞÀÏÀ» Æ÷ÇÔ½ÃÄѶó. // ÀúÀÚ : Al Dev Email: alavoor@yahoo.com // Usage : ptags *.php3 *.inc // This will generate a file called tags //***************************************************************** #include #include #include // for sprintf #include // for system #include // for memset #include // for isspace #define BUFF_LEN 1024 #define LOCATION 9 char *ltrim(char *dd); char *rtrim(char *ee); main(int argc, char **argv) { if (argc < 2) { cerr << "\nUsage: " << argv[0] << " file .... " << endl; exit(0); } char fname[100] = "tag_file.out"; FILE *fpout; ofstream fout(fname); if (fout.fail()) { cerr << "\nError opening file : " << fname << endl; exit(-1); } //fpout = fopen(fname, "w"); for (int ii = 1; ii < argc; ii++) { /* char buff[2024]; sprintf(buff, "\\rm -f %s; ls %s > %s 2>/dev/null", outfile, argv[1], outfile); cout << "\nbuff = " << buff << endl; system(buff); fclose(fp); */ FILE *fpin = NULL; fpin = fopen(argv[ii], "r"); if (fpin == NULL) { cerr << "\nError opening file : " << argv[ii] << endl; exit(-1); } char buff[BUFF_LEN + 100]; memset(buff, 0, BUFF_LEN +10); for ( ; fgets(buff, BUFF_LEN, fpin) != NULL; ) { char aa[BUFF_LEN + 100]; memset(aa, 0, BUFF_LEN +10); strcpy(aa, buff); ltrim(aa); // Remove the trailing new line.. { int tmpii = strlen(aa); if (aa[tmpii-1] == '\n') aa[tmpii-1] = 0; } //cout << "aa is : " << aa << endl; if (strncmp(aa, "function ", LOCATION) != 0) continue; //cout << buff << endl; // Example tags file output is like - // al2 al.c /^al2()$/;" f { char bb[BUFF_LEN + 100]; memset(bb, 0, BUFF_LEN +10); strcpy(bb, & aa[LOCATION]); char *cc = bb; while (cc != NULL && *cc != '(') *cc++; *cc = 0; cc = rtrim(bb); //cout << "bb is : " << bb << endl; //cout << cc << "\t" << argv[ii] << "\t" << "/^" << aa << "$/;\"\tf" << endl; fout << cc << "\t" << argv[ii] << "\t" << "/^" << aa << "$/;\"\tf" << endl; //fprintf(fpout, "%s\t%s\t/^%s$/;\"f\n", cc, argv[ii], aa ); } memset(buff, 0, BUFF_LEN +10); } fclose(fpin); } fout.flush(); fout.close(); //fclose(fpout); // Sort and generate the tag file { char tmpaa[1024]; sprintf(tmpaa, "sort %s > tags; \\rm -f %s", fname, fname); system(tmpaa); } } char *ltrim(char *dd) { if (dd == NULL) return NULL; while (isspace(*dd)) dd++; return dd; } char *rtrim(char *ee) { if (ee == NULL) return NULL; int tmpii = strlen(ee) - 1; for (; tmpii >= 0 ; tmpii--) { if (isspace(ee[tmpii]) ) { //cout << "\nis a space!!" << endl; ee[tmpii] = 0; } } return ee; } ______________________________________________________________________ 6. PHP µð¹ö±ë PHP ÇÁ·Î±×·¥À» µð¹ö±ë ÇÏ·Á¸é ´ÙÀ½ÀÇ ÇÔ¼ö¸¦ °¡Áö´Â "debug2.inc"À̶õ È­ÀÏÀ» ¸¸µé¾î¶ó : ______________________________________________________________________ File open failed - global.var.inc"; exit; } function debug2_($fname, $lname, $debug_var, $debug_value=0) { global $fp_debug2; //print "
debug_value is : $debug_value
"; if (!$debug_value) { fwrite($fp_debug2, "\n ". $fname ." ". $lname .": $debug_var"); } else { fwrite($fp_debug2, "\n ". $fname . " ". $lname .": $debug_var = $debug_value"); } //print "
f_cookie is : $f_cookie
"; } // In your first page, which is generally index.php3 // truncate the debug2_logs file in beginning of code function init_debug_file() { global $fp_debug2; $fp_debug2 = fopen("/debug2_logs/debug.out", "w"); if ($fp_debug2 == false) { print "File open failed - global.var.inc"; exit; } system("chmod a+rwx /debug2_logs/debug.out"); } ?> ______________________________________________________________________ º¸Åë index.php3·Î µÇ´Â ½ÃÀÛÆäÀÌÁöÀÇ PHP ¼Ò½ºÄڵ忡 ´ÙÀ½À» Áý¾î³Ö¾î¶ó. ______________________________________________________________________ ______________________________________________________________________ µð¹ö±ë °ªÀ» ¾ò±âÀ§ÇØ PHP ¼Ò½ºÄÚµå ÆÄÀÏ¿¡ debug2_() ¶õ È£ÃâÀ» ¾Æ·¡¿Í °°ÀÌ ³Ö¾î¶ó ______________________________________________________________________ ______________________________________________________________________ PHP ÇÁ·Î±×·¥À» ½ÇÇàÇÏ°Ô µÇ¸é, °á°ú°¡ debug.out À̶õ È­ÀÏ¿¡ ÆÄÀÏÀ̸§, ¶óÀιøÈ£, º¯¼ö¸í °ú º¯¼ö°ªÀÌ ³ªÅ¸³­´Ù. ÀϹøÀûÀ¸·Î debug2_()¸¦ »ç¿ëÇ϶ó. ÇÁ·Î±×·¥¿¡¼­ debug2_()ÀÇ È£ÃâÀº ÃÖÁ¾°á°ú Äڵ忡 ¾î¶°ÇÑ ¿µÇâµµ ÁÖÁö¾ÊÀ¸¸ç ½ÇÇà¿¡µµ ¾Æ¹«·± ¿µÇâÀ» ÁÖÁö¾Ê´Â´Ù. ¿Ö³ÄÇÏ¸é ¾Æ·¡¿¡ ±â¼úÇÑ°Í °°ÀÌ ÇÊÅ͸µ µÇ±â ¶§¹®ÀÌ´Ù. debug2_()¸¦ ŸÀÌÇÎÇÏ´Â ½Ã°£À» ÁÙÀ̱â À§ÇØ º¹»ç(copy)¿Í ºÙ¿©³Ö±â(paste)¸¦ »ç¿ëÇÒ¼ö ÀÖ´Ù. ¶ÇÇÑ Vi ¿¡µðÅÍÀÇ 'yank to buffer' ±â´ÉÀ» ÀÌ¿ëÇؼ­ º¹»çÇ϶ó. °³¹ßÀÌ ¿Ï·áµÇ¸é Å×½ºÆ®ÇÏ°í ¼­¹ö¿¡ ¿Ã¸° Áغñ°¡ µÆÀ¸¸é ¼Ò½ºÄڵ忡¼­ debug2_ È£ÃâÀ» ÇÊÅ͸µ Ç϶ó. À¯´Ð½º ÇÁ·ÒÇÁÆ®¿¡¼­ - ______________________________________________________________________ bash$ mkdir production bash$ grep -v debug2_ filea.php3 > production/filea.php3 ______________________________________________________________________ ¿©·¯°³ÀÇ È­ÀÏÀÌ ÀÖÀ¸¸é - ______________________________________________________________________ bash$ mkdir production bash$ ls *.php3 | while read ans do grep -v debug2_ $ans > production/$ans done ______________________________________________________________________ ±×¸®°í ÀÌÁ¦ production ¿¡¼­ °³¹ßÇϴ°÷(¿µ¿ª)À» º¹»çÇ϶ó. 7. PHPÀÇ Á¦ÇÑ ¸ðµç »ç¶÷ÀÌ ÇÑ°è¿Í ´ÜÁ¡ÀÌ ÀÖµíÀÌ PHPµµ ¿¹¿Ü°¡ ¾Æ´Ï´Ù. ¾Æ·¡¿¡ Àִ°ÍÀº PHPÀÇ Á¦¾à(ÇÑ°è)ÀÌ´Ù.(±×·¡¼­ °æ°íÇÑ´Ù !!) 1. PHP´Â 100% ¼ø¼öÇÑ °´Ã¼ÁöÇâ ½ºÅ©¸³Æ® ¾ð¾î°¡ ¾Æ´Ï´Ù. PHP´Â ÄÚµåÀÇ Å©±â°¡ 300,000 ¶óÀÎÀ» ³ÑÁö ¾ÊÀ¸¸é ±¦Âù´Ù. 300,000 ¶óÀÎÀÌ ³Ñ´Â PHPÄڵ带 °ü¸®Çϱâ´Â Á»´õ Èûµé¾îÁú°ÍÀÌ´Ù. 2. PHP´Â "C"³ª "C++" ¾ð¾îÀÇ ¼º´ÉÀ» ÁÖÁö ¸ðÇÑ´Ù. ¿Ö³ÄÇϸé PHP´Â ½ºÅ©¸³Æ® ¾ð¾îÀÌ°í ½ÇÇà¹æ½ÄÀÌ ÀÎÅÍÇÁ¸®ÅÍ Çü½ÄÀ̱⠶§¹®¿¡ ÃÖÀûÈ­µÈ "C++"º¸´Ù ´Ù¼Ò ´À¸®´Ù. ÃÖ°íÀÇ ¼º´ÉÀ» ¿øÇÑ´Ù¸é "C++"°ú Ä¿³Ø¼Ç Ç®¸µ(connection pooling)µÈ µ¥ÀÌŸº£À̽º/¿û¼­¹ö¿Í ¿¬µ¿µÈ ºü¸¥ CGI ¸¦ »ç¿ëÇÏ°í C++ ÄÄÆÄÀÏ·¯ ¿ÉƼ¸¶ÀÌÁ®¸¦ "-03" ¿É¼ÇÀ» »ç¿ëÇ϶ó. PHP 4¿¡ ÀÖ´ÂÁ¨µå¿ÉƼ¸¶ÀÌÁ®´Â PHPÀÇ ¼º´ÉÀ» ¾î´ÀÁ¤µµ Çâ»ó½Ãų°ÍÀÌ´Ù. ÇÑÆíÀ¸·Î´Â PHP´Â ¸¹Àº ÀåÁ¡À» °¡Áö°í ±× ÀåÁ¡Àº Á¦ÇÑÀ» º¸ÃæÇÒ¼ö ÀÖ´Ù - 1. PHP ½ºÅ©¸³Æ® ¾ð¾î¿¡¼­´Â ÄÄÆÄÀÏ°ú ¸µÅ©°¡ »ý·«µÇ±â ¶§¹®¿¡ ¸Å¿ì ºü¸£°Ô À¥¾îÇø®ÄÉÀ̼ÇÀ» °³¹ßÇÒ¼öÀÖ´Ù. 2. PHP ¿¡Çø®ÄÉÀ̼ÇÀº ¸Å¿ì ¾ÈÁ¤ÀûÀÌ°í ÀÚ¹Ù½ºÅ©¸³Æ®°¡ ºê¶ó¿ìÁ®¿¡ ÀÇÁ¸ÀûÀΰͰú ´Ù¸£°Ô ºê¶ó¾ÆÁ®ÀÇ ±â¼ú¿¡ ÀÇÁ¸ÀûÀÌÁö ¾Ê´Ù. PHP´Â ¾î¶² ¼­¹ö Ç÷¿Æû°ú ¾î¶² ºê¶ó¿ìÁ®¸¦ ¼±ÅÃÇؾßÇÏ´Â °Í¿¡ ´ëÇÑ ÀÚÀ¯¸¦ ÁÖ°í ºê¶ó¿ìÁ®´Â HTML ÀÌ PHP°¡ ¸¸µé¾î³Â´Ù´Â °ÍÀ» ¸ð¸¥´Ù! 3. PHP´Â ¸ðµç SQL Å×ÀÌÅͺ£À̽º ¼­¹ö¿ÍÀÇ ¿¬°á¼ºÀÌ ¶Ù¾î³ª´Ù. 4. PHP´Â ºÎºÐÀûÀ¸·Î °´Ã¼ÁöÇâ Ư¼ºÀ» °¡Áö°í ÀÖ´Ù. 5. PHP´Â "C++", Perl, Javascript¿Í ºñ½ÁÇÑ ¹®¹ýÀ» °¡Áö°í ¼Ò½ºÄڵ带 Ž»öÇÒ¼ö ÀÖ´Â ÇÁ·Î±×·¥°ú ºñ½ÁÇÑ 'ptags/ctags'¸¦ °¡Áö°í ÀÖ´Ù. 6. PHP´Â ¼Óµµ¸¦ Çâ»ó½Ãų¼ö ÀÖ´Â Á¨µå¿ÉƼ¸¶ÀÌÁ®¸¦ °¡Áö°í ÀÖ´Ù. 7. PHP´Â ¸ðµç À¯´Ð½ºµé, ¸®´ª½º, À©µµ 95/NT/200 ¿¡¼­ ½ÇÇàµÇ¸ç ASP, JSP¿Í ´Ù¸¥°Íº¸´Ù ¼º´ÉÀÌ ÁÁ´Ù. 8. PHP´Â ¸¹Àº »ç¿ëÀÚÃþ¿Í °³¹ßÀÚÃþÀ» °¡Áö°í ÀÖ´Ù. °æ°í: ¸¸¾à 100% ¼ø¼öÇÑ °´Ã¼ÁöÇâ ½ºÅ©¸³Æ® ¾ð¾î¸¦ ¿øÇÑ´Ù¸é "¹Ýµå½Ã" PythonÀ» ¿°µÎÇضó. 'Python'Àº óÀ½ºÎÅÍ °´Ã¼ÁöÇâ ½ºÅ©¸³Æ®¾ð¾îÀÌ´Ù. ¿¡ ÀÖ´Ù. 8. °ü°èÀÖ´Â URLµé C, C++¿¡ °ü°èÀÖ´Â ´ÙÀ½ Àå¼Ò¸¦ ¹æ¹®Ç϶ó - o C++, CÀ» À§ÇÑ Ä÷¯ Vim ÅؽºÆ® ¿¡µðÅÍ o PHP PostgreSQL¸¦ À§ÇÑ SQL database server o C++ ÇÁ·Î±×·¥À» À§ÇÑ Source code control system CVS HOWTO o Linux goodies main site o Linux goodies mirror site 9. À̹®¼­ÀÇ ´Ù¸¥ Æ÷¸ä À̹®¼­´Â DVI, Postscript, Latex, Adobe Acrobat PDF, LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages ¿Í SGML 11°¡ÁöÀÇ ´Ù¸¥ Æ÷¸äÀÌ ÀÖ´Ù. o ÀÌ HOWTO ¹®¼­À» HTML, DVI, Postscritp ¶Ç´Â SGML Æ÷¸äÀ¸·Î µÈ tar ball ÆÄÀÏÀ» ¿¡¼­ ±¸ÇÒ¼ö ÀÖ´Ù. o ´Ü¼øÇÑ ÅؽºÆ® Æ÷¸äÀº ¿¡¼­ o ºÒ¾î, µ¶¾î, ¼­¹Ý¾Æ¾î, Áß±¹¾î, ÀϺ»¾î·Î ¹ø¿ªµÈ ¹®¼­´Â ¿¡¼­ ±¸ÇÒ¼ö ÀÖ´Ù. ´Ù¸¥ ¾ð¾î·Î ¹ø¿ªÇÏ½Ç ºÐÀÇ µµ¿òÀ» ȯ¿µÇÑ´Ù. À̹®¼­´Â ¿¡¼­ ±¸ÇÒ¼ö ÀÖ´Â "SGML-Tools"¶õ ÅøÀ» »ç¿ëÇؼ­ ÀÛ¼ºµÇ¾ú´Ù. ´ÙÀ½°ú °°Àº ¸í·ÉÀ» »ç¿ëÇؼ­ ¼Ò½º¸¦ ÄÄÆÄÀÏ ÇÒ¼ö ÀÖ´Ù. o sgml2html CVS-HOWTO.sgml (html È­ÀÏÀ» ¸¸µé±â À§ÇØ) o sgml2rtf CVS-HOWTO.sgml (RTF È­ÀÏÀ» ¸¸µé±â À§ÇØ) o sgml2latex CVS-HOWTO.sgml (latex È­ÀÏÀ» ¸¸µé±â À§ÇØ) LaTex ¹®¼­´Â sgml2latex (¿Í dvips) ±×¸®°í ¾ÆÅ©·Î¹ÙÆ®(Acrobat) distill ( ) À» »ç¿ëÇÑ Æ÷½ºÆ®½ºÅ©¸³Æ® °á°ú 󸮷ΠPDFÈ­ÀÏ·Î ½±°Ô ¹Ù²Ü¼ö ÀÖ´Ù. ´ÙÀ½À½ ¸í·ÉµéÀÌ´Ù: ______________________________________________________________________ bash$ man sgml2latex bash$ sgml2latex filename.sgml bash$ man dvips bash$ dvips -o filename.ps filename.dvi bash$ distill filename.ps bash$ man ghostscript bash$ man ps2pdf bash$ ps2pdf input.ps output.pdf bash$ acroread output.pdf & ______________________________________________________________________ ¶Ç´Â °í½ºÆ®½ºÅ©¸³(Ghostscript) ¸í·É ps2pdfÀ» »ç¿ëÇÒ¼ö ÀÖ´Ù. ps2pdf´Â Adobe's Acrobat Distiller product ÀÇ °ÅÀÇ ¸ðµç ±â´É°ú ºñ½ÁÇÏ°Ô µ¿ÀÛÇÑ´Ù. Æ÷½ºÆ®½ºÅ©¸³Æ® È­ÀÏÀ» PDF(Portable Document Format)À¸·Î ¹Ù²Ù¾îÁØ´Ù. ps2pdf´Â ¸í·É ½ºÅ©¸³Æ®(command script/¹èÄ¡ÆÄÀÏ)°¡ Ghostscript¸¦ ºÒ·¯³»°í , pdfwrite¶ó°í ºÒ¸®´Â Ưº°ÇÑ Ãâ·Â µð¹ÙÀ̽º¸¦ ¼±ÅÃÇÏ¿© ½ÇÇàµÈ´Ù. ps2pdf¸¦ »ç¿ëÇϱâ À§ÇØ Ghostscript¸¦ ÄÄÆÄÀÏ ÇÒ¶§ pdfwrite ÀåÄ¡°¡ makefile¿¡ Æ÷ÇԵǾî¾ßÇÑ´Ù; ÀÚ¼¼ÇÑ °ÍÀº Ghostscript ¼³Ä¡ ¹®¼­¸¦ º¸¾Æ¶ó. À̹®¼­´Â ´ÙÀ½¿¡¼­ ãÀ»¼ö ÀÖ´Ù - o ¶ÇÇÑ ´ÙÀ½ÀÇ ¹Ì·¯ »çÀÌÆ®¿¡¼­ À̹®¼­¸¦ ãÀ»¼ö ÀÖ´Ù - o o o o o ´Ù¸¥ ´ç½Å°ú °¡±î¿î ¹Ì·¯»çÀÌÆ®(network-address-wise)´Â ¿¡¼­ ãÀ»¼ö ÀÖ´Ù. »çÀÌÆ®¸¦ ¼±ÅÃÇÏ°í /LDP/HOWTO/CVS-HOWTO.html µð·ºÅ丮°í °¡¶ó. ±× dvi Æ÷¸äÀ¸·Î µÇ¾îÀÖ´Â ±× ¹®¼­¸¦ º¸±âÀ§Çؼ­´Â xdvi¶õ ÇÁ·Î±×·¥À» »ç¿ëÇ϶ó. xdvi ÇÁ·Î±×·¥Àº ·¡µåÇÞ ¸®´ª½ºÀÇ tetex-xdvi*.rpm ÆÐÅ°Áö¿¡ ÀÖ°í ¸Þ´º¹öÆ° ControlPanel | Applications | Publishing | TeX ¿¡ ÀÖ´Ù. dvi ¹®¼­¸¦ Àбâ À§ÇØ ´ÙÀ½ÀÇ ¸í·ÉÀ» ½ÇÇàÇ϶ó - xdvi -geometry 80x90 howto.dvi man xdvi ±×¸®°í ¸¶¿ì½º¸¦ »ç¿ëÇÏ¿© À©µµ¿ì Å©±â¸¦ Á¶ÀýÇ϶ó. È­»ìǥŰ, Page Up, Page Down keys ¿Í À§, ¾Æ·¡, Áß°£, ´ÙÀ½ÆäÀÌÁö, Àü ÆäÀÌÁö µîÀ» Ž»öÇÒ¼ö ÀÖ´Ù. ½ÇÇàÀ» ³¡³»·Á¸é 'x'¸¦ ´­·¯¶ó. È­ÀÏÀ» ÀÐÀ»¼ö ÀÖ´Ù. ·¡µåÇÞ ¸®´ª½º¿¡¼­ ghostscript ´Â ghostscript*.rpm ÆÐÅ°Áö¿¡ gv´Â gv*.rpm ÆÐÅ°Áö¿¡ ÀÖ´Ù. ±×¸®°í ControlPanel | Applications | Graphics ¸Þ´º ¹öÆ°¿¡ À§Ä¡ÇÑ´Ù. gv °¡ ghostscriptº¸´Ù ´õ Ä£±ÙÇÑ ÇÁ·Î±×·¥ÀÌ´Ù. ±×¸®°í ghostscript¿Í gv´Â OS/2, Windows 95 ¿Í NT ¿ëµµ Á¸ÀçÇÑ´Ù. ±×¸®°í ±× ¿î¿ëüÁ¦¿¡¼­ ÀÌ ¹®¼­µµ º¼¼ö ÀÖ´Ù. o Get ghostscript for Windows 95, OS/2, and for all OSes from Æ÷½ºÆ®½ºÅ©¸³Æ® ¹®¼­¸¦ Àбâ À§ÇØ ´ÙÀ½À» ÀÔ·ÂÇ϶ó - gv howto.ps ghostscript howto.ps ³×½ºÄÉÀÌÇÁ ³×ºñ°ÔÀÌÅÍ, ¸¶ÀÌÅ©·Î¼ÒÇÁÆ® ÀÎÅÍ³Ý ÀͽºÆú·Î·¯, ·¡µåÇÞ ¹Ù·Ð À¥ºê¶ó¿ìÁ® ¶Ç´Â 10°¡Áö ÀÌ»óÀÇ À¥ºÎ¶ó¿ìÁ®¿¡¼­ HTML Æ÷¸Ë¹®¼­¸¦ ÀÐÀ»¼ö ÀÖ´Ù. LyX ¶ó´Â X-Windows¿ë ÇÁ·Î±×·¥À¸·Î latex ¹®¼­¸¦ ÀÐÀ»¼ö ÀÖ´Ù. 10. ÀúÀÛ±Ç ÀúÀÛ±ÇÁ¤Ã¥Àº LDP(¸®´ª½º ¹®¼­ ÇÁ·ÎÁ§Æ®)ÀÇ GNU/GPLÀ» µû¸¥´Ù. LDP´Â GNU/GPL ÇÁ·ÎÁ§Æ®ÀÌ´Ù. Ãß°¡ÀûÀÎ ¿ä±¸ - ÀúÀÛÀÚÀÇ À̸§, À̸ÞÀÏÁÖ¼Ò¿Í ÀÌ ÀúÀ۱ǻçÇ×À» À¯ÁöÇ϶ó. ¸¸¾à ´ç½ÅÀÌ À̹®¼­¿¡ ¾î¶°ÇÑ ¼öÁ¤À̳ª ÷°¡¸¦ ÇÒ°æ¿ì À̹®¼­ÀÇ ÀúÀÚ¿¡°Ô ¾Ë·ÁÁÖ¾î¶ó. 11. ºÎ·Ï A Database Wrapper ¿¹Á¦ Á¦ÃâÀÚ : Barton Greg greg@createtech.com ÀÌÈ­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÁ®¿¡¼­ '´Ù¸¥À̸§À¸·Î ÀúÀå'À» ´©¸£°í pgsql.lib ¶ó°í ÀÔ·ÂÇϽÿÀ. ______________________________________________________________________ ÀÌ°ÍÀº PostgresSQLÀ» À§ÇÑ µ¥ÀÌÅͺ£À̽º ·¦ÆÛÀÌÁö¸¸ ´Ù¸¥ Çü½ÄÀÇ µ¥ÀÌÅͺ£À̽º¸¦ À§ÇØ Á¶±Ý¸¸ °íÄ¡¸é »ç¿ëÇÒ¼ö ÀÖ´Ù. host; if(isset($parame[user])) $user = $parame[user]; else $user = $this->user; if(isset($parame[password])) $password = $parame[password]; else $password = $this->password; if(isset($parame[port])) $port = $parame[port]; else $port = $this->port; if(isset($parame[dbname])) $dbname = $parame[dbname]; else $dbname = $this->dbname; $this->conn = pg_Connect ( " host=$host user=$user password=$password port=$port dbname=$dbname "); } // Send SQL to database connection. // Return recordset object on success. // Return 0 on failure. function exec($SQL) { $this->resultset = pg_Exec($this->conn, $SQL); if ($this->resultset) { $recset = new recordset; $recset->init($this->resultset); return $recset; } else { return 0; } } function valid() { return $this->resultset; } // Close connection to database function free() { pg_close($this->conn); } }; /* ** This is a simple recordset class which can be ** traversed using next(), prev(), and current() methods. ** It is initialized from a resultset returned from the ** function "pg_Exec" or can be generated by a call to the ** exec method from the dbObj class given above. ** Below "Tuples" means rows. */ class recordset { var $resultset; var $index; var $numFields; var $numTuples; function init($newResultset) { $this->resultset = $newResultset; $this->index = 0; $this->numFields = pg_NumFields($this->resultset); $this->numTuples = pg_NumRows($this->resultset); } // Used in display() below function valid() { return $this->resultset; } // Get a value by row number and either // column name or column number function getVal($row, $col) { return pg_Result($this->resultset, $row, $col); } // Return an array of field names function getFields() { for ($i=0; $i < $this->numFields; $i++) $retArray[] = pg_FieldName($this->resultset, $i); return $retArray; } // Get number of columns in resultset function getNumFields() { return $this->numFields; } // Get a tuple (associative array of // column values) by row number function getTupleDirect($row) { for ($i=0; $i < $this->numFields; $i++) { $retArray[pg_FieldName($this->resultset, $i)] = pg_Result($this->resultset, $row, $i); } return $retArray; } // Get an array filled with all values in a column // (using either column name or column number) function getColumn($col) { for ($i=0; $i < $this->numTuples; $i++) $retArray[] = pg_Result($this->resultset, $i, $col); return $retArray; } // Return the number of records in the recordset function getNumTuples() { return $this->numTuples; } // Get tuple pointed to by the current index function getTuple() { if ($this->index >= 0 && $this->index < $this->numTuples) return $this->getTupleDirect($this->index); else return 0; } function valueof($col) { if ($col < $this->numFields) { return pg_Result($this->resultset, $this->index, $col); } else { return ""; } } // Reached last row - end of rows ? Used in display() below function eof() { return $this->index == $this->numTuples; } // Return 1 if index is within bounds of the recordset function current() { if ($this->index >= 0 && $this->index < $this->numTuples) return 1; else return 0; } // Increment index. Used in display() below function next() { if ($this->index < $this->numTuples) { $this->index++; return 1; } else { return 0; } } // Decrement index function prev() { if ($this->index >= 0) { $this->index--; return 1; } else { return 0; } } // Reset index to 0 - See also first() function reset() { $this->index = 0; } // See also reset(). Used in display() below function first() { $this->index = 0; } function last() { $this->index = $this->numTuples -1 ; } // Used in display() below function showheader($col, $fmt = "") { printf("\t< th %s>%s< /th >\n", $fmt, is_string($col) ? $col : pg_fieldname($this->resultset, $col)); } // Used in display() below function showvalue($col, $fmt = "", $def = " ") { $v = $this->valueof($col); printf( "\t< td %s>%s< /td>\n", $fmt, $v == "" ? $def : $v); } function showurl($col, $fmt = "") { $v = $this->valueof($col); if ( $v != "" ) { printf("\t< td %s> < /td>\n", $fmt); } else { printf( "\t< td %s>< a href=%s>%s< /a>< /td>\n", $fmt, $v, $v); } } function display() { if (!$this->valid() ) { return; } printf( "\n"); printf( "\n"); for ($c = 0; $c < $this->cols; $c++ ) { $this->showheader($c); } printf( "< /tr>\n"); $this->first(); while (!$this->eof()) { printf( "\n"); for ($c = 0; $c < $this->cols; $c++) { $this->showvalue($c); } printf( "< /tr>\n"); $this->next(); } printf("< /table\n"); } // Free memory allocated to recordset. function free() { pg_Freeresult($this->resultset); } }; } ?> ______________________________________________________________________ 12. ºÎ·Ï B SQL abstraction Example Á¦ÃâÀÚ : Gianugo Rabellino nemorino@opera.it ÀÌÈ­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÁ®¿¡¼­ '´Ù¸¥À̸§À¸·Î ÀúÀå'À» ´©¸£°í sqlabst.lib ¶ó°í ÀÔ·ÂÇϽÿÀ. ______________________________________________________________________ PX: PHP Code Exchange ______________________________________________________________________ 14. ºÎ·Ï D »ç¿ëÀÚ ÀÎÁõ ¿¹Á¦ ÀÌÈ­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÁ®¿¡¼­ '´Ù¸¥À̸§À¸·Î ÀúÀå'À» ´©¸£°í user_pw.lib ¶ó°í ÀÔ·ÂÇϽÿÀ. PHP 3 ¸Þ´º¾ó¿¡¼­ : PHP°¡ ¾ÆÆÄÄ¡ ¸ðµâÀ϶§¸¸ ÀÛµ¿ÇÑ´Ù. $PHP_AUTH_USER ¿Í $PHP_AUTH_PW ¸¦ Ãâ·ÂÇÏ´Â ´ë½Å, »ç¿ëÀÚÀ̸§°ú ºñ¹Ð¹øÈ£¸¦ È®Àθ¸ ÇϱâÀ» ¿øÇÒÁöµµ ¸ð¸¥´Ù. ¾Æ¸¶µµ µ¥ÀÌÅͺ£À̽º¿¡ Äõ¸®¸¦ º¸³»°Å³ª adm È­ÀÏ¿¡¼­ ã¾Æº¸¸é µÉ°ÍÀÌ´Ù. ______________________________________________________________________ "; echo "You entered $PHP_AUTH_PW as your password.

"; } ?> ______________________________________________________________________ 15. ºÎ·Ï E ³×Æ®¿öÅ© °ü¸® ¿¹Á¦ ÀÌ È­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÀú¿¡¼­ network.lib¶õ À̸§ÀÇ 'ÅؽºÆ®(Text)' ÇüÅ·ΠÀúÀåÇ϶ó. PHP: network adminstrator's best friend from À¥°³¹ßÀڷμ­ ¾Æ¸¶ ping, whois, nslookup µîµîÀÇ À¯¿ëÇÑ ÅøÀ» »ç¿ëÇÒ°ÍÀÌ´Ù. ±×·¯³ª °í°´ÀÇ »ç¹«½Ç¿¡¼­ ±× ÅøÁß Çϳª¸¦ »ç¿ëÇؾߵǴµ¥ telnetÀ» »ç¿ëÇÒ¼ö ¾ø´Ù¸é ¾î¶»°ÔÇÒ°ÍÀΰ¡? PHP ¸Å´º¾óÀÇ '³×Æ®¿öÅ©'¿¡¼­ functionÀ» ã¾Æº¸´Â °ÍÀÌ ´ë¾ÈÀÌ´Ù. ¼ÒÄÏ ÀÛµ¿ : °¡Àå Áß¿äÇÑ ÇÔ¼ö´Â fsockopen()ÀÌ´Ù. ÀÌÇÔ¼ö¸¦ »ç¿ëÇÏ¸é ¼­¹öÀÇ ¿­·ÁÁø ¾î¶² Æ÷Æ®·Îµµ Á¢¼ÓÇÒ¼ö ÀÖ°í ¼ÒÄÏÀÇ ¿¬°áÀ» ¼³Á¤ÇÒ¼ö ÀÖ´Ù. ÇÔ¼öÀÇ ¹®¹ýÀº ´ÙÀ½°ú °°´Ù : ______________________________________________________________________ int fsockopen(string hostname, int port, int [errno], string [errstr]); ______________________________________________________________________ ¾ÕÀÇ 2°³ÀÇ º¯¼ö´Â ½±°Ô ¾Ë¼ö ÀÖ°í, ´ÙÀ½ÀÇ 2°³ÀÇ º¯¼ö´Â ¿É¼ÇÀÌ°í, ¿¡·¯¸¦ ó¸®Çϱâ À§ÇØ ¾²ÀδÙ. "errno"°ú "errstr"Àº ÂüÁ¶¸¦ ÅëÇؼ­ ÀÌ·ç¾îÁ®¾ß ÇÑ´Ù. "ÂüÁ¶¸¦ ÅëÇØ ÀÌ·ç¾îÁø´Ù"´Â ¸»ÀÇ Àǹ̴ ¿ø·¡ÀÇ º¯¼ö°¡ º¯ÇÑ´Ù´Â ¸»ÀÌ´Ù. º¸Åë, ÇÔ¼ö°¡ ½ÇÇàµÇ´õ¶óµµ º¯¼öÀÇ ³»¿ëÀº º¯ÇÏÁö ¾Ê´Â´Ù. ±×·¡¼­, À¥¼­¹ö¿¡ ¿¬°áÇϱâ À§ÇØ ÀÌÇÔ¼ö¸¦ »ç¿ëÇÏ°í Çì´õ¸¦ ÇÁ¸°Æ®Ç϶ó : ______________________________________________________________________ function get_headers($host, $path = "/") { $fp = fsockopen ("$host", 80, &$errnr, &$errstr) or die("$errno: $errstr"); fputs($fp,"GET $path HTTP/1.0\n\n"); while (!$end) { $line = fgets($fp, 2048); if (trim($line) == "") $end = true; else echo $line; } fclose($fp); } ______________________________________________________________________ ÀÌ ¿¹Á¦¿¡¼­´Â fsockopen()À» È£ÃâÇؼ­ ¾òÀº ÆÄÀÏÆ÷ÀÎÅÍ¿Í ÆÄÀÏ󸮿¡ °üÇÑÀÀ¿ëÀ» ¾Ë¾Æº¼°ÍÀÌ´Ù.(fred, fwrite µîµî) HTTP/1.0 Ŭ¶óÀ̾ðÆ®¿¡¼­¸¸ ±¸ÇöµÈ´Ù´Â°ÍÀ» ¸í½ÉÇ϶ó. - name-based °¡»óÈ£½ºÆ®¿¡¼­´Â µ¿ÀÛÇÏÁö ¾Ê´Â´Ù. Áö½Ã: ÀϹÝÀûÀ¸·Î ´Ù¸¥ Æ÷Æ®·Î ¿¬°á ÇÒ¼ö ÀÖ´Ù. PHP·Î ÀÛÀº ÇΰŠŬ¶óÀ̾ðÆ®¸¦ ¸¸µç°ÍÀº ½¬°Ô ÇÒ¼ö ÀÖ´Ù. ÇΰŠµ¥¸ó¿¡ Äõ¸®(Áú¹®)Çϱâ À§ÇØ ¾Æ·¡¿¡ ÀÖ´Â ¿¹Á¦¸¦ ¼öÁ¤Ç϶ó. ______________________________________________________________________ function finger ($host, $user) { $fp = fsockopen($host, 79, &$errno, &$errstr) or die("$errno: $errstr"); fputs($fp, "$user\n"); while (!feof($fp)) echo fgets($fp, 128); fclose($fp); } ______________________________________________________________________ Whois: ÈÄÀ̽º(whois) ¼­¹ö¿¡ Áú¹®Çϴ°͵µ °°Àº °³³äÀÌ´Ù: ______________________________________________________________________ // domain is like "phpwizard.net" function whois($domain, $server="whois.internic.net") { $fp = fsockopen ($server, 43, &$errnr, &$errstr) or die("$errno: $errstr"); fputs($fp, "$domain\n"); while (!feof($fp)) echo fgets($fp, 2048); fclose($fp); } ______________________________________________________________________ ºí·°Å·, ³Íºí·ÏÅ· Á¦¾î : ±×·¯³ª ÀÌÇÔ¼ö¸¦ »ç¿ëÇϴµ¥ ¹®Á¦°¡ ÀÖ´Ù. ´ÙÀ½°ú °°À»¶§¸¸ ÀßÀÛµ¿ÇÑ´Ù. 1. È£Ãâ½Ã°£ÀÌ ÀÛÀº ¿¬°áÀ϶§¿Í 2. ¿¬°áÇÏ°í ÀÖ´Â ¼­¹ö°¡ »ì¾ÆÀÖ°í ÀÛµ¿ÇÒ¶§. ±×·¸Áö ¾ÊÀ¸¸é, ´ç½ÅÀÇ ½ºÅ©¸³Æ®´Â Á¾·áµÉ¶§±îÁö ÀÛµ¿ÇÑ´Ù. ±×·¸°Ô µÇ´Â ÀÌÀ¯´Â ¼ÒÄÏ¿¬°áÀº ºí·°Å·µÇ¸ç Á¾·á°¡ µÇÁö¾Ê±â ¶§¹®ÀÌ´Ù. set_socket_blocking()À̶õ ÇÔ¼ö´Â ´ÙÀ½°ú °°ÀÌ µ¿ÀÛÇÑ´Ù: ÇÔ¼ö´Â ¸ðµçµ¿ÀÛÀ» ¼ÒÄÏ(ù¹ø° Àμö:¼ÒÄÏ Æ÷ÀÎÅÍ)¿¡ ºí·°Å·(µÎ¹øÀç Àμö:true)³ª Æú½º(false)(¼¼¹ø° Àμö:false)·Î ¼³Á¤ÇÑ´Ù. ³Íºí·°Å·Á¦¾î¸¦ »ç¿ëÇϸé, ÇΰÅ(finger)ÇÔ¼ö´Â ´ÙÀ½°ú °°À»°ÍÀÌ´Ù:(¿ªÁÖ:¹«½¼¸»ÀÎÁö ¹ø¿ªÀÌ ÀÌ»óÇϳ׿ä) ______________________________________________________________________ $fp = fsockopen($host, 79, &$errno, &$errstr) or die("$errno: [ ] $errstr"); set_socket_blocking($fp, 0); fputs($fp, "$user\n"); $stop = time() + $timeout; while (!feof($fp) && time() < $stop ) echo fgets($fp, 128); fclose($fp); ______________________________________________________________________ ³Íºí·¯Å· ¼ÒÄÏÄÝ(socket calls)À» »ç¿ëÇϱâ À§ÇÑ 3°³ÀÇ ÇÔ¼öÀÇ ¼öÁ¤Àº ´ç½ÅÀÇ ¿¬½ÀÀ» À§ÇØ ³²°ÜµÐ´Ù. 16. ºÎ·Ï F PostgreSQL Database Wrapper ¿¹Á¦ Á¦ÃâÀÚ : Joe Thong darkjoe@softhome.net »çÀÌÆ® URL: ¼³¸í: ¿©·¯°¡Áö µ¥ÀÌÅͺ£À̽º ¼­¹ö¿¡¼­ °á°ú Á¶ÀÛÀ» À§ÇÑ °­·ÂÇÑ PHP µ¥ÀÌŸº£À̽º ·¦ÆÛ. µ¥ÀÌÅͺ£À̽ºÀÇ °á°ú°¡ phpDB¿¡ ÀÇÇØ ÀÚµ¿À¸·Î ³ª¿À°Ô µÈ´Ù. ÀÌÈ­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÁ®¿¡¼­ '´Ù¸¥À̸§À¸·Î ÀúÀå'À» ´©¸£°í phpDB- postgresql.lib ¶ó°í ÀÔ·ÂÇϽÿÀ. ______________________________________________________________________ databaseType = $dbType; break; default: return false; } } // Returns: A positive link identifier on success, or // false on error. Connect to the server with the provided // arguments. The connection to the server will be closed // when the script terminates, unless close() function is // called beforehand function connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") { $connString = ""; $hostPieces = array(); /* Must specify the database argument */ if (!$argDatabaseName) { return false; } if ($argHostname != "") { $this->hostname = $argHostname; } if ($argUsername != "") { $this->username = $argUsername; } if ($argPassword != "") { $this->password = $argPassword; } if ($argDatabaseName != "") { $this->databaseName = $argDatabaseName; } $hostPieces = split(":", $this->hostname); if ($hostPieces[0]) { $connString .= "host=$hostPieces[0]"; if (isset($hostPieces[1])) { $connString .= " port=$hostPieces[1]"; } } if ($this->username) { $connString .= " user=$this->username"; } if ($this->password) { $connString .= " password=$this->password"; } $connString .= " dbname=$this->databaseName"; $this->_connectionID = @pg_Connect($connString); return $this->_connectionID; } // Returns: A positive link identifier on success, or // false on error. Connect to the server with the // provided arguments. The connection to the server will // not be closed when the script terminates. Instead it // will be kept for later future use function pconnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") { $connString = ""; $hostPieces = array(); /* Must specify the database argument */ if (!$argDatabaseName) { return false; } if ($argHostname != "") { $this->hostname = $argHostname; } if ($argUsername != "") { $this->username = $argUsername; } if ($argPassword != "") { $this->password = $argPassword; } if ($argDatabaseName != "") { $this->databaseName = $argDatabaseName; } $hostPieces = split(":", $this->hostname); if ($hostPieces[0]) { $connString .= "host=$hostPieces[0]"; if (isset($hostPieces[1])) { $connString .= " port=$hostPieces[1]"; } } if ($this->username) { $connString .= " user=$this->username"; } if ($this->password) { $connString .= " password=$this->password"; } $connString .= " dbname=$this->databaseName"; $this->_connectionID = @pg_pConnect($connString); if ($this->_connectionID) { $this->_isPersistentConnection = true; } return $this->_connectionID; } // Returns: true on success, false on error Select // the database name to be used PostgreSQL // Note: function Not available function selectDB($dbName) { return false; } // Returns: the Recordset object disregard success // or failure Send the sql statement to the database server function execute($sql = "") { // Instantiate an object without considering whether // the query return any results or not $this->_queryID = @pg_Exec($this->_connectionID, $sql); $this->_tempResultObj = new Recordset($this->_queryID); $this->_insertQuery($this->_queryID); return $this->_tempResultObj; } // Returns: the last error message from previous // database operation function errorMsg() { $this->_errorMsg = @pg_errormessage($this->_connectionID); return $this->_errorMsg; } // Returns: true on success, false on failure // Close the database connection function close() { if ($this->_queryIDList && sizeof($this->_queryIDList > 0)) { while(list($_key, $_resultID) = each($this->_queryIDList)) { @pg_freeresult($_resultID); } } // If its not a persistent connection, then // only the connection needs to be closed if ($this->_isPersistentConnection != true) { return @pg_close($this->_connectionID); } else { return true; } } // A PRIVATE function used by the constructor function // of the query object. insert the successful returned // query id to the query id list. Used for later results // cleanup. A private function that's never meant to // be used directly function _insertQuery($query_id) { $this->_queryIDList[] = $query_id; } } //------------------------------ Class Name: Recordset //------------------------------ class Recordset { /* public variables */ var $fields; // indicates that the current record position is before // the first record in a Recordset object var $BOF = null; // indicates that the current record position is after // the last record in a Recordset object var $EOF = null; /* private variables */ var $_numOfRows = -1; // NEVER change the value! READ-ONLY! var $_numOfFields = -1; // NEVER change the value! READ-ONLY! // Holds anything that was returned from the database specific functions var $_tempResult = ''; // This variable keeps the result link identifier var $_queryID = -1; // This variable keeps the current row in the Recordset var $_currentRow = -1; // Returns: query id on success and false if // failed Constructor function function Recordset($queryID) { $this->_queryID = $queryID; if ($queryID) { $this->_numOfRows = @pg_numrows($this->_queryID); /* pg_numrows() returns -1 on error */ if ($this->_numOfRows == -1) { $this->_numOfRows = 0; } $this->_numOfFields = @pg_numfields($this->_queryID); /* pg_numfields() returns -1 on error */ if ($this->_numOfFields == -1) { $this->_numOfFields = 0; } } else { $this->_numOfRows = 0; $this->_numOfFields = 0; } /* If result set contains rows */ if ($this->_numOfRows > 0 && $this->_currentRow == -1) { $this->_currentRow = 0; $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow); $this->EOF = false; $this->BOF = false; } return $this->_queryID; } // Returns: true if successful, false if fail Set the Recordset // pointer to a specified field offset. If the next call to // fetchField() won't include a field offset, this field would // be returned. PostgreSQL Note: function Not available function fieldSeek($fieldOffset = -1) { $this->_tempResult = false; return $this->_tempResult; } // Returns: an object containing field information. Get column // information in the Recordset object. fetchField() can be used // in order to obtain information about fields in a certain query // result. If the field offset isn't specified, the next field // that wasn't yet retrieved by fetchField() is retrieved. // PostgreSQL Note: function Not available function fetchField($fieldOffset = -1) { $this->_tempResult = false; return $this->_tempResult; } // Returns: true if there still rows available, or false if there // are no more rows. Moves to the next row in a specified Recordset // object and makes that record the current row and the data // corresponding to the row will be retrieved into the fields // collection. Note: Unlike the moveRow() method, when _currentRow // is getNumOfRows() - 1, EOF will immediately be true. If row number // is not provided, the function will point to the // first row automatically function nextRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $this->_currentRow++; $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow); /* This is not working. True all the time */ if ($this->fields) { $this->_checkAndChangeEOF($this->_currentRow - 1); return true; } } $this->EOF = true; return false; } // Returns: true on success, false on failure moveRow() moves // the internal row pointer of the Recordset object to point // to the specified row number and the data corresponding to // the row will be retrieved into the fields collection. If // row number is not provided, the function will point to // the first row automatically function moveRow($rowNumber = 0) { if ($rowNumber == 0) { return $this->firstRow(); } else if ($rowNumber == ($this->getNumOfRows() - 1)) { return $this->lastRow(); } if ($this->getNumOfRows() > 0 && $rowNumber < $this->getNumOfRows()) { $this->fields = null; $this->_currentRow = $rowNumber; $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow); /* This is not working. True all the time */ if ($this->fields) { // No need to call _checkAndChangeEOF() because // the possibility of moving to the last row // has been handled by the above code $this->EOF = false; return true; } } $this->EOF = true; return false; } // Returns: true on success, false on failure firstRow() // moves the internal row pointer of the Recordset object // to the first row and the data corresponding to the row // will be retrieved into the fields collection function firstRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $this->_currentRow = 0; $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow); $this->EOF = true; /* This is not working. True all the time */ if ($this->fields) { return true; } } $this->EOF = true; return false; } // Returns: true on success, false on failure lastRow() // moves the internal row pointer of the Recordset object // to the last row and the data corresponding to the row // will be retrieved into the fields collection function lastRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $num_of_rows = $this->getNumOfRows(); /* $num_of_rows decemented at above */ $this->_currentRow = --$num_of_rows; $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow); /* This is not working. True all the time */ if ($this->fields) { /* Special case for making EOF false. */ $this->EOF = false; return true; } } $this->EOF = true; return false; } // close() only needs to be called if you are worried about // using too much memory while your script is running. All // associated result memory for the specified result identifier // will automatically be freed function close() { $this->_tempResult = @pg_freeresult($this->_queryID); return $this->_tempResult; } // Returns: the number of rows in a result set. // Get number of rows in result function getNumOfRows() { return $this->_numOfRows; } // Returns: the number of fields in a result set. // Get number of fields in result function getNumOfFields() { return $this->_numOfFields; } /* Check and change the status of EOF. */ function _checkAndChangeEOF($currentRow) { if ($currentRow >= ($this->_numOfRows - 1)) { $this->EOF = true; } else { $this->EOF = false; } } } ?> ______________________________________________________________________ 17. ºÎ·Ï G Microsoft SQL Server DB Wrapper ¿¹Á¦ Á¦ÃâÀÚ : Joe Thong darkjoe@softhome.net Site URL: ¼³¸í: ¿©·¯°¡Áö µ¥ÀÌÅͺ£À̽º ¼­¹ö¿¡¼­ °á°ú Á¶ÀÛÀ» À§ÇÑ °­·ÂÇÑ PHP µ¥ÀÌŸº£À̽º ·¦ÆÛ. µ¥ÀÌÅͺ£À̽ºÀÇ °á°ú°¡ phpDB¿¡ ÀÇÇØ ÀÚµ¿À¸·Î ³ª¿À°Ô µÈ´Ù. ÀÌÈ­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÁ®¿¡¼­ '´Ù¸¥À̸§À¸·Î ÀúÀå'À» ´©¸£°í phpDB- msql.lib ¶ó°í ÀÔ·ÂÇϽÿÀ. ______________________________________________________________________ databaseType = $dbType; break; default: return false; } } // Returns: A positive link identifier on success, // or false on error. Connect to the server with // the provided arguments. The connection to the server // will be closed when the script terminates, unless // close() function is called beforehand. function connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") { $boolDBSelected; if ($argHostname != "") { $this->hostname = $argHostname; } if ($argUsername != "") { $this->username = $argUsername; } if ($argPassword != "") { $this->password = $argPassword; } if ($argDatabaseName != "") { $this->databaseName = $argDatabaseName; } $this->_connectionID = @mssql_connect($this->hostname, $this->username, $this->password); if ($this->databaseName && $this->_connectionID) { $boolDBSelected = @mssql_select_db($this->databaseName); if(!$boolDBSelected) { /* If DB selection fails */ @mssql_close($this->_connectionID); /* Close the current connection */ return false; } } return $this->_connectionID; } // Returns: A positive link identifier on success, or // false on error Connect to the server with the provided // arguments. The connection to the server will not be closed // when the script terminates. Instead it will be kept for // later future use function pconnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") { $boolDBSelected; if ($argHostname != "") { $this->hostname = $argHostname; } if ($argUsername != "") { $this->username = $argUsername; } if ($argPassword != "") { $this->password = $argPassword; } if ($argDatabaseName != "") { $this->databaseName = $argDatabaseName; } $this->_connectionID = @mssql_pconnect($this->hostname, $this->username, $this->password); if ($this->_connectionID) { $this->_isPersistentConnection = true; } if ($this->databaseName && $this->_connectionID) { $boolDBSelected = @mssql_select_db($this->databaseName); if(!$boolDBSelected) { /* if DB selection fails */ return false; /* Persistent connection can't be closed */ } } return $this->_connectionID; } // Returns: true on success, false on error Select the // database name to be used function selectDB($dbName) { $this->databaseName = $dbName; if ($this->_connectionID) { return @mssql_select_db($dbName); } else { /* No database selected */ return false; } } // Returns: the Recordset object disregard success or // failure Send the sql statement to the database server function execute($sql = "") { $this->_queryID = @mssql_query($sql, $this->_connectionID); // Instantiate an object without considering whether // the query return any results or not $this->_tempResultObj = new Recordset($this->_queryID); $this->_insertQuery($this->_queryID); return $this->_tempResultObj; } // Returns: the last error message from previous database // operation Note: This function is NOT available for // Microsoft SQL Server function errorMsg() { $this->_errorMsg = "errorMsg() is not available for Microsoft SQL Server"; return $this->_errorMsg; } /* Returns: true on success, false on failure Close the database connection. */ function close() { if ($this->_queryIDList && sizeof($this->_queryIDList > 0)) { while(list($_key, $_resultID) = each($this->_queryIDList)) { @mssql_free_result($_resultID); } } // If its not a persistent connection, then // only the connection needs to be closed if ($this->_isPersistentConnection != true) { return @mssql_close($this->_connectionID); } else { return true; } } // A PRIVATE function used by the constructor function of // the query object. insert the successful returned // query id to the query id list. Used for later results // cleanup. A private function that's never meant to be // used directly function _insertQuery($query_id) { $this->_queryIDList[] = $query_id; } } //--------------------------------------- Class Name: Recordset //--------------------------------------- class Recordset { /* public variables */ var $fields; // indicates that the current record position is // before the first record in a Recordset object var $BOF = null; // indicates that the current record position is // after the last record in a Recordset object var $EOF = null; // Private variables var $_numOfRows = -1; // NEVER change the value! READ-ONLY! var $_numOfFields = -1; // NEVER change the value! READ-ONLY! // Holds anything that was returned from the // database specific functions var $_tempResult = ''; // This variable keeps the result link identifier var $_queryID = -1; // This variable keeps the current row in the Recordset var $_currentRow = -1; // Returns: query id on success and false if // failed Constructor function function Recordset($queryID) { $this->_queryID = $queryID; if ($queryID) { $this->_numOfRows = @mssql_num_rows($this->_queryID); $this->_numOfFields = @mssql_num_fields($this->_queryID); } else { $this->_numOfRows = 0; $this->_numOfFields = 0; } // If result set contains rows if ($this->_numOfRows > 0 && $this->_currentRow == -1) { $this->_currentRow = 0; $this->fields = @mssql_fetch_array($this->_queryID); $this->EOF = false; $this->BOF = false; } return $this->_queryID; } // Returns: true if successful, false if fail Set // the Recordset pointer to a specified field offset. // If the next call to fetchField() won't include a // field offset, this field would be returned function fieldSeek($fieldOffset = -1) { $this->_tempResult = @mssql_field_seek($this->_queryID, $fieldOffset); return $this->_tempResult; } // Returns: an object containing field information. // Get column information in the Recordset object. // fetchField() can be used in order to obtain information // about fields in a certain query result. If the field // offset isn't specified, the next field that wasn't yet // retrieved by fetchField() is retrieved function fetchField($fieldOffset = -1) { if ($fieldOffset != -1) { $this->_tempResult = @mssql_fetch_field($this->_queryID, $fieldOffset); } // The $fieldOffset argument is not provided thus its -1 else if ($fieldOffset == -1) { $this->_tempResult = @mssql_fetch_field($this->_queryID); } return $this->_tempResult; } // Returns: true if there still rows available, or false // if there are no more rows. Moves to the next row in a // specified Recordset object and makes that record the current // row and the data corresponding to the row will be retrieved // into the fields collection. Note: Unlike the moveRow() method, // when _currentRow is getNumOfRows() - 1, EOF will immediately be // true. If row number is not provided, the function will point // to the first row automatically function nextRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $this->_currentRow++; $this->fields = @mssql_fetch_array($this->_queryID); // This is not working. True all the time if ($this->fields) { $this->_checkAndChangeEOF($this->_currentRow - 1); return true; } } $this->EOF = true; return false; } // Returns: true on success, false on failure moveRow() // moves the internal row pointer of the Recordset object // to point to the specified row number and the data // corresponding to the row will be retrieved into the fields // collection. If row number is not provided, the function will // point to the first row automatically function moveRow($rowNumber = 0) { if ($rowNumber == 0) { return $this->firstRow(); } else if ($rowNumber == ($this->getNumOfRows() - 1)) { return $this->lastRow(); } if ($this->getNumOfRows() > 0 && $rowNumber < $this->getNumOfRows()) { $this->fields = null; $this->_currentRow = $rowNumber; if(@mssql_data_seek($this->_queryID, $this->_currentRow)) { $this->fields = @mssql_fetch_array($this->_queryID); /* This is not working. True all the time */ if ($this->fields) { // No need to call _checkAndChangeEOF() because // the possibility of moving to the last row has // been handled by the above code $this->EOF = false; return true; } } } $this->EOF = true; return false; } // Returns: true on success, false on failure firstRow() moves // the internal row pointer of the Recordset object to the first // row and the data corresponding to the row will be retrieved // into the fields collection function firstRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $this->_currentRow = 0; if (@mssql_data_seek($this->_queryID, $this->_currentRow)) { $this->fields = @mssql_fetch_array($this->_queryID); $this->EOF = false; /* This is not working. True all the time */ if ($this->fields) { return true; } } } $this->EOF = true; return false; } // Returns: true on success, false on failure lastRow() moves // the internal row pointer of the Recordset object to the last // row and the data corresponding to the row will be retrieved // into the fields collection function lastRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $num_of_rows = $this->getNumOfRows(); $this->_tempResult = @mssql_data_seek($this->_queryID, --$num_of_rows); if ($this->_tempResult) { /* $num_of_rows decemented at above */ $this->_currentRow = $num_of_rows; $this->fields = @mssql_fetch_array($this->_queryID); /* This is not working. True all the time */ if ($this->fields) { /* Special case for making EOF false. */ $this->EOF = false; return true; } } } $this->EOF = true; return false; } // close() only needs to be called if you are worried about using // too much memory while your script is running. All associated // result memory for the specified result identifier will // automatically be freed function close() { $this->_tempResult = @mssql_free_result($this->_queryID); return $this->_tempResult; } // Returns: the number of rows in a result set. Get // number of rows in result function getNumOfRows() { return $this->_numOfRows; } /* Returns: the number of fields in a result set. Get number of fields in result. */ function getNumOfFields() { return $this->_numOfFields; } /* Check and change the status of EOF. */ function _checkAndChangeEOF($currentRow) { if ($currentRow >= ($this->_numOfRows - 1)) { $this->EOF = true; } else { $this->EOF = false; } } } ?> ______________________________________________________________________ 18. ºÎ·Ï H Sybase SQL Server DB Wrapper ¿¹Á¦ Á¦ÃâÀÚ : Joe Thong darkjoe@softhome.net Site URL: ¼³¸í: ¿©·¯°¡Áö µ¥ÀÌÅͺ£À̽º ¼­¹ö¿¡¼­ °á°ú Á¶ÀÛÀ» À§ÇÑ °­·ÂÇÑ PHP µ¥ÀÌŸº£À̽º ·¦ÆÛ. µ¥ÀÌÅͺ£À̽ºÀÇ °á°ú°¡ phpDB¿¡ ÀÇÇØ ÀÚµ¿À¸·Î ³ª¿À°Ô µÈ´Ù. ÀÌÈ­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÁ®¿¡¼­ '´Ù¸¥À̸§À¸·Î ÀúÀå'À» ´©¸£°í phpDB- sybase.lib ¶ó°í ÀÔ·ÂÇϽÿÀ. ______________________________________________________________________ databaseType = $dbType; break; default: return false; } } // Returns: A positive link identifier on success, or // false on error. Connect to the server with the // provided arguments. The connection to the server will be // closed when the script terminates, unless close() // function is called beforehand function connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") { $boolDBSelected; if ($argHostname != "") { $this->hostname = $argHostname; } if ($argUsername != "") { $this->username = $argUsername; } if ($argPassword != "") { $this->password = $argPassword; } if ($argDatabaseName != "") { $this->databaseName = $argDatabaseName; } $this->_connectionID = @sybase_connect($this->hostname, $this->username, $this->password); if ($this->databaseName && $this->_connectionID) { $boolDBSelected = @sybase_select_db($this->databaseName); /* If DB selection fails */ if(!$boolDBSelected) { /* Close the current connection */ @sybase_close($this->_connectionID); return false; } } return $this->_connectionID; } // Returns: A positive link identifier on success, or false // on error. Connect to the server with the provided // arguments. The connection to the server will not be closed // when the script terminates. Instead it will be kept for later future use function pconnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") { $boolDBSelected; if ($argHostname != "") { $this->hostname = $argHostname; } if ($argUsername != "") { $this->username = $argUsername; } if ($argPassword != "") { $this->password = $argPassword; } if ($argDatabaseName != "") { $this->databaseName = $argDatabaseName; } $this->_connectionID = @sybase_pconnect($this->hostname, $this->username, $this->password); if ($this->_connectionID) { $this->_isPersistentConnection = true; } if ($this->databaseName && $this->_connectionID) { $boolDBSelected = @sybase_select_db($this->databaseName); /* if DB selection fails */ if(!$boolDBSelected) { /* Persistent connection can't be closed */ return false; } } return $this->_connectionID; } /* Returns: true on success, false on error Select the database name to be used */ function selectDB($dbName) { $this->databaseName = $dbName; if ($this->_connectionID) { return @sybase_select_db($dbName); } else { /* No database selected */ return false; } } /* Returns: the Recordset object disregard success or failure Send the sql statement to the database server. */ function execute($sql = "") { $this->_queryID = @sybase_query($sql, $this->_connectionID); // Instantiate an object without considering whether // the query return any results or not $this->_tempResultObj = new Recordset($this->_queryID); $this->_insertQuery($this->_queryID); return $this->_tempResultObj; } /* Returns: the last error message from previous database operation Note: This function is NOT available for Sybase. */ function errorMsg() { $this->_errorMsg = "errorMsg() is not available for Sybase"; return $this->_errorMsg; } /* Returns: true on success, false on failure Close the database connection. */ function close() { if ($this->_queryIDList && sizeof($this->_queryIDList > 0)) { while(list($_key, $_resultID) = each($this->_queryIDList)) { @sybase_free_result($_resultID); } } // If its not a persistent connection, then // only the connection needs to be closed if ($this->_isPersistentConnection != true) { return @sybase_close($this->_connectionID); } else { return true; } } // A PRIVATE function used by the constructor function // of the query object. insert the successful returned // query id to the query id list. Used for later results // cleanup. A private function that's never meant // to be used directly function _insertQuery($query_id) { $this->_queryIDList[] = $query_id; } } //---------------------------------- Class Name: Recordset //---------------------------------- class Recordset { /* public variables */ var $fields; // indicates that the current record position is // before the first record in a Recordset object var $BOF = null; // indicates that the current record position // is after the last record in a Recordset object var $EOF = null; // Private variables - starts with underscore var $_numOfRows = -1; // NEVER change the value! READ-ONLY! var $_numOfFields = -1; // NEVER change the value! READ-ONLY! // Holds anything that was returned from // the database specific functions var $_tempResult = ''; // This variable keeps the result link identifier var $_queryID = -1; // This variable keeps the current row in the Recordset var $_currentRow = -1; // Returns: query id on success and false if // failed Constructor function function Recordset($queryID) { $this->_queryID = $queryID; if ($queryID) { $this->_numOfRows = @sybase_num_rows($this->_queryID); $this->_numOfFields = @sybase_num_fields($this->_queryID); } else { $this->_numOfRows = 0; $this->_numOfFields = 0; } /* If result set contains rows */ if ($this->_numOfRows > 0 && $this->_currentRow == -1) { $this->_currentRow = 0; $this->fields = @sybase_fetch_array($this->_queryID); $this->EOF = false; $this->BOF = false; } return $this->_queryID; } // Returns: true if successful, false if fail Set // the Recordset pointer to a specified field offset. // If the next call to fetchField() won't include a // field offset, this field would be returned function fieldSeek($fieldOffset = -1) { $this->_tempResult = @sybase_field_seek($this->_queryID, $fieldOffset); return $this->_tempResult; } // Returns: an object containing field information. // Get column information in the Recordset object. // fetchField() can be used in order to obtain information // about fields in a certain query result. If the field // offset isn't specified, the next field that wasn't yet // retrieved by fetchField() is retrieved function fetchField($fieldOffset = -1) { if ($fieldOffset != -1) { $this->_tempResult = @sybase_fetch_field($this->_queryID, $fieldOffset); } /* The $fieldOffset argument is not provided thus its -1 */ else if ($fieldOffset == -1) { $this->_tempResult = @sybase_fetch_field($this->_queryID); } return $this->_tempResult; } // Returns: true if there still rows available, or // false if there are no more rows. Moves to the next // row in a specified Recordset object and makes that record // the current row and the data corresponding to the row will // be retrieved into the fields collection. Note: Unlike // the moveRow() method, when _currentRow is getNumOfRows() - 1, // EOF will immediately be true. If row number is not // provided, the function will point to the // first row automatically function nextRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $this->_currentRow++; $this->fields = @sybase_fetch_array($this->_queryID); /* This is not working. True all the time */ if ($this->fields) { $this->_checkAndChangeEOF($this->_currentRow - 1); return true; } } $this->EOF = true; return false; } // Returns: true on success, false on failure moveRow() // moves the internal row pointer of the Recordset object // to point to the specified row number and the data // corresponding to the row will be retrieved into the // fields collection. If row number is not provided, the // function will point to the first row automatically function moveRow($rowNumber = 0) { if ($rowNumber == 0) { return $this->firstRow(); } else if ($rowNumber == ($this->getNumOfRows() - 1)) { return $this->lastRow(); } if ($this->getNumOfRows() > 0 && $rowNumber < $this->getNumOfRows()) { $this->fields = null; $this->_currentRow = $rowNumber; if(@sybase_data_seek($this->_queryID, $this->_currentRow)) { $this->fields = @sybase_fetch_array($this->_queryID); /* This is not working. True all the time */ if ($this->fields) { // No need to call _checkAndChangeEOF() // because the possibility of moving to the // last row has been handled by the above code $this->EOF = false; return true; } } } $this->EOF = true; return false; } // Returns: true on success, false on failure firstRow() // moves the internal row pointer of the Recordset object // to the first row and the data corresponding to the row // will be retrieved into the fields collection function firstRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $this->_currentRow = 0; if (@sybase_data_seek($this->_queryID, $this->_currentRow)) { $this->fields = @sybase_fetch_array($this->_queryID); $this->EOF = false; /* This is not working. True all the time */ if ($this->fields) { return true; } } } $this->EOF = true; return false; } // Returns: true on success, false on failure lastRow() // moves the internal row pointer of the Recordset object // to the last row and the data corresponding to the row // will be retrieved into the fields collection function lastRow() { if ($this->getNumOfRows() > 0) { $this->fields = array(); $num_of_rows = $this->getNumOfRows(); $this->_tempResult = @sybase_data_seek($this->_queryID, --$num_of_rows); if ($this->_tempResult) { /* $num_of_rows decemented at above */ $this->_currentRow = $num_of_rows; $this->fields = @sybase_fetch_array($this->_queryID); /* This is not working. True all the time */ if ($this->fields) { /* Special case for making EOF false. */ $this->EOF = false; return true; } } } $this->EOF = true; return false; } // close() only needs to be called if you are worried // about using too much memory while your script is // running. All associated result memory for the // specified result identifier will automatically be freed function close() { $this->_tempResult = @sybase_free_result($this->_queryID); return $this->_tempResult; } /* Returns: the number of rows in a result set. Get number of rows in result. */ function getNumOfRows() { return $this->_numOfRows; } /* Returns: the number of fields in a result set. Get number of fields in result. */ function getNumOfFields() { return $this->_numOfFields; } /* Check and change the status of EOF. */ function _checkAndChangeEOF($currentRow) { if ($currentRow >= ($this->_numOfRows - 1)) { $this->EOF = true; } else { $this->EOF = false; } } } ?> ______________________________________________________________________ 19. ºÎ·Ï I phpDB.inc ¿¹Á¦ Á¦ÃâÀÚ : Joe Thong darkjoe@softhome.net Site URL: Description: ¿©·¯°¡Áö µ¥ÀÌÅͺ£À̽º ¼­¹ö¿¡¼­ °á°ú Á¶ÀÛÀ» À§ÇÑ °­·ÂÇÑ PHP µ¥ÀÌŸº£À̽º ·¦ÆÛ. µ¥ÀÌÅͺ£À̽ºÀÇ °á°ú°¡ phpDB¿¡ ÀÇÇØ ÀÚµ¿À¸·Î ³ª¿À°Ô µÈ´Ù. ÀÌÈ­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÁ®¿¡¼­ '´Ù¸¥À̸§À¸·Î ÀúÀå'À» ´©¸£°í phpDB.inc ¶ó°í ÀÔ·ÂÇϽÿÀ. ______________________________________________________________________ ______________________________________________________________________ 20. ºÎ·Ï J phpDBTest.php3 ¿¹Á¦ Á¦ÃâÀÚ : Joe Thong darkjoe@softhome.net Site URL: ¼³¸í: ¿©·¯°¡Áö µ¥ÀÌÅͺ£À̽º ¼­¹ö¿¡¼­ °á°ú Á¶ÀÛÀ» À§ÇÑ °­·ÂÇÑ PHP µ¥ÀÌŸº£À̽º ·¦ÆÛ. µ¥ÀÌÅͺ£À̽ºÀÇ °á°ú°¡ phpDB¿¡ ÀÇÇØ ÀÚµ¿À¸·Î ³ª¿À°Ô µÈ´Ù. ÀÌÈ­ÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÁ®¿¡¼­ '´Ù¸¥À̸§À¸·Î ÀúÀå'À» ´©¸£°í phpDB- mssql.lib ¶ó°í ÀÔ·ÂÇϽÿÀ.(¿ªÁÖ: phpDB-mssql.lib °¡ ¾Æ´Ï°í. phpDBTest.php3 ¶ó°íÇؾßÇÕ´Ï´Ù.) ______________________________________________________________________ < head> < title>Untitled< /title> < /head> < body> pconnect("hostName", "userName", "passWord", "databaseName") or die ("Can't connect to database server or select database"); $rs = $db->execute("SELECT * FROM Items"); $numOfRows = $rs->getNumOfRows(); echo "Number of Rows: $numOfRows"; $rs->firstRow(); // ¼±ÅûçÇ×À̳ª, ÃßõÇÕ´Ï´Ù. while (!$rs->EOF) { // Fields collection accessible as associative arrays too echo "
" . $rs->fields[0]; $rs->nextRow(); // NOTE: nextRow() is placed at below } $rs->close(); $db->close(); // ¼±ÅûçÇ× ?> < /body> < /html> ______________________________________________________________________