· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Docbook Sgml/APM_tip-KLDP

APM ÆÁ ¸ðÀ½

APM ÆÁ ¸ðÀ½

±è¿ëÀÏ

$Date: 2003/08/07 01:04:21 $

ȨÆäÀÌÁö¸¦ ¸¸µé¸é¼­ ±×µ¿¾È Á¶±×¸¶ÇÑ ÆÁÀ» ¸ð¾Æ ³õÀº °ÍÀÔ´Ï´Ù.

고친 과정
고침 0.12002-11-16고친이 ±è ¿ëÀÏ
ÃÖÃÊ ÀÛ¼º

차례
1. ¼Ò°³
1.1. À̱ÛÀº
1.2. µ¡±Û
1.3. µµ¿Í ÁֽźÐ
1.4. ÀúÀÛ±Ç
2. ¼³Ä¡
3. Apache
4. Html
5. Perl
5.1. ÆÞ »ç¿ëÇϱâ À§ÇÑ apache, mysql ¼³Á¤
5.2. µð·ºÅ丮, È­ÀÏ ¸¸µé±â
5.3. ½Ã°£ Ãâ·Â¹× Å×ÀÌºí ³»¿ë Ãâ·Â
5.4. À̸§À» ÀÔ·Â¹Þ¾Æ mysql¿¡ ÀúÀåÇÏ°í Ãâ·ÂÇϱâ
5.5. ÀÔ·Â ¹Þ´Â ºÎºÐÀ» üũ Çϱâ
6. Php
6.1. ³ëÇÁ·¹ÀÓ ¸¸µå´Â¹ý
6.2. À̸§À» ÀÔ·Â¹Þ¾Æ mysql¿¡ ÀúÀåÇÏ°í Ãâ·ÂÇϱâ
6.3. À̸§À» ÀÔ·Â¹Þ¾Æ Ã¼Å©ÇÏ°í mysql¿¡ ÀúÀåÇÏ°í Ãâ·ÂÇϱâ
6.4. Å×À̺í Ãâ·Â ÇÁ·Î±×·¥
6.5. mysql_fetch_array ¿¹Á¦
6.6. À̹ÌÁö È­ÀÏ Ãâ·Â
6.7. ´Þ·Â ¿¹Á¦
6.8. ¿øÇÏ´Â ¹®ÀÚ¿­ °Ë»ö(ereg)
6.9. ÀÎÁõ ¿¹Á¦
6.10. Ä¿³Î ¹öÀü ³ªÅ¸³»ÁÖ´Â ÇÔ¼ö
6.11. µµ¸ÞÀΠǥ½Ã ÇÔ¼ö
6.12. ¹®ÀÚ¿­ üũ ÇÔ¼ö ¿¹Á¦(ereg)
6.13. IDüũ ÇØÁÖ´Â ÇÁ·Î±×·¥
6.14. °Ô½Ã¹° ÆäÀÌÁö º¯°æ ¿¹Á¦
6.15. Á¤±ÔÇ¥Çö½Ä
6.16. ¿µ¾î ´Ü¾î °Ë»ö
6.17. IP ¼Ò¼Ó±â°ü,ȸ»ç ¾Ë¾Æº¸±â
6.18. ÇöÀçÀÇ ³â/¿ù/ÀÏ ±¸Çϱâ
7. ÀÚ¹Ù½ºÅ©¸³Æ®
7.1. idcheck¸¦ À§ÇÑ ¿¹Á¦
7.2. ¸Þ´º ¸¸µé±â ¿¹Á¦
8. Oracle
9. Mysql
9.1. mysql ÁÖ±âÀûÀ¸·Î ¹é¾÷Çϱâ
9.2. mysql ·çÆ® Æнº¿öµå¸¦ ÀÒ¾î ¹ö·ÈÀ» ¶§
9.3. µ¥ÀÌŸ ŸÀÔ (Å×ÀÌºí »ý¼º½Ã Ä÷³ÀÇ µ¥ÀÌŸ ŸÀÔÀÔ´Ï´Ù.)
9.4. ½©¿¡¼­ DB ³»¿ë º¸±â
9.5. Mysql¿¡ µé¾î°¡±â
9.1. µ¥ÀÌŸ ¹é¾÷ ¹Þ±â (È­ÀÏ·Î ¹ÞÀ½)
9.2. µ¥ÀÌŸ ÀÔ·ÂÇϱâ (È­ÀÏ--> Mysql)
9.3. »ç¿ëÀÚ ¸¸µé±â
9.4. Å×ÀÌºí ¸¸µé±â
9.5. Å×ÀÌºí º¸±â
9.6. Å×ÀÌºí µ¥ÀÌŸ ÀÔ·ÂÇϱâ
9.7. ƯÁ¤ Çʵ常 ÀÔ·Â
9.8. Å×ÀÌºí³»¿ë º¸±â
9.9. Çʵå Ãß°¡
9.10. ÇÊµå »èÁ¦
9.11. ±âŸ alter ¿ë¹ý
9.12. µ¥ÀÌŸ »èÁ¦
9.13. µ¥ÀÌŸ ¼öÁ¤
9.14. ³»¸² Â÷¼øÀ¸·Î Á¤·Ä
9.15. ¹«ÀÛÀ§ Á¤·Ä
9.16. ³âµµ¼øÀ¸·Î Á¤·Ä
9.17. ³âµµ, ¹øÈ£¼øÀ¸·Î Á¤·Ä
9.18. 20»ì ÀÌ»óÀÌ ¸î¸íÀΰ¡¸¦ ã´Â´Ù.
9.19. null °ª °Ë»öÇϱâ
9.1. null °ª °Ë»öÇϱâ
9.2. °Ë»ö Çϱâ
9.3. ¹üÀ§ °Ë»ö
9.4. in °Ë»ö
9.5. not in °Ë»ö
9.6. ³¯Â¥ °Ë»öÇϱâ
9.7. Å×ÀÌºí ³»¿ëÀ» È­ÀÏ·Î ¸¸µé±â
9.8. Å×ÀÌºí ³»¿ëÀ» È­ÀÏ·Î ¸¸µé¶§ |·Î ±¸ºÐÇϱâ
9.9. È­ÀÏÀ» ºÒ·¯¿À±â

1. ¼Ò°³

1.1. À̱ÛÀº

ȨÆäÀÌÁö¸¦ ¸¸µé¸é¼­ ±×µ¿¾È Á¶±×¸¶ÇÑ ÆÁÀ» ¸ð¾Æ ³õÀº °ÍÀÔ´Ï´Ù.

apache, mysql, php, perl ¿¡ °ü·ÃµÈ ¹®¼­ ÀÔ´Ï´Ù.


1.2. µ¡±Û

ÇѱÛÀ» »ì¸®°í ³ª¶ó¸¦ »ì¸®´Â ±æÀº, °úÇÐÀûÀ¸·Î À¸¶ä°¡´Â ¼¼¹ú½ÄÀ» »ç¿ëÇÏ´Â °Í»ÓÀÔ´Ï´Ù.

´ëÇѹα¹ °úÇбâ¼úÀ» »ì¸®´Â±æÀº ½¬¿î Çѱ۷ΠµÈ ¹®¼­¸¦ ¸¸µå°ÍÀÔ´Ï´Ù. ¿Ü±¹¹®¼­¸¦ ÀÚ±â È¥ÀÚ¸¸ º¸°í ¸»°ÍÀÌ ¾Æ´Ï¶ó, ½±°Ô ¹ø¿ª, º¸ÃæÇؼ­ ÃÊÁß°í»ýµé·Î º¼¼ö ÀÖ°Ô ÇØ¾ß ÇÕ´Ï´Ù.

³ª¶ó¸¦ Àß »ì°í, ºÎ°­ÇÏ°Ô ÇØ¾ß ÇÏ´Â ÀÌÀ¯´Â ´Ù¸¥³ª¶ó³ª, ÀÎÁ¾¿¡°Ô ¼­·¯¿òÀ» ¹ÞÁö ¾Ê±â Çϱâ À§ÇÔÀÔ´Ï´Ù.


1.3. µµ¿Í ÁֽźÐ

°ü·Ã¼­Àû°ú ¿©·¯ ÀÎÅÍ³Ý »çÀÌÆ®¸¦ ¿î¿µÇÏ°í °è½Å ºÐµé²² °¨»çÇÕ´Ï´Ù.


1.4. ÀúÀÛ±Ç

ÀÌ ¹®¼­´Â GNU Free Documentation License ¹öÀü 1.1 ȤÀº ÀÚÀ¯ ¼ÒÇÁÆ®¿þ¾î Àç´Ü¿¡¼­ ¹ßÇàÇÑ ÀÌÈÄ ÆÇÀÇ ±ÔÁ¤¿¡ µû¸£¸ç ÀúÀ۱ǿ¡ ´ëÇÑ º» »çÇ×ÀÌ ¸í½ÃµÇ´Â ÇÑ ¾î¶°ÇÑ Á¤º¸ ¸Åü¿¡ ÀÇÇÑ º»¹®ÀÇ ÀüÀ糪 ¹ßÃéµµ ¹«»óÀ¸·Î Çã¿ëµË´Ï´Ù.

º» ÀúÀÚ´Â ¹®¼­ÀÇ ³»¿ëÀÌ ¾ß±âÇÒ ¼ö ÀÖ´Â ¾î¶°ÇÑ °á°ú¿¡ ´ëÇؼ­µµ Ã¥ÀÓÀ» ÁöÁö ¾Ê½À´Ï´Ù.


2. ¼³Ä¡

  • ´Ù¿î·Îµå¸¦ ÇÕ´Ï´Ù.

    http://www.mysql.com/downloads/index.html

    http://apache.org/

  • ¾ÐÃàÀ» Ç®±â

    tar xvfz mysql-3.23.7-alpha.tar.gz
    tar xvfz apache_1.3.12.tar.gz
    tar xvfz php-4.0.1.tar.gz
    tar xvfz ZendOptimizer-Beta2-Linux-glibc2.1.tar.gz
        

  • Mysql

    cd mysql-3.23.7-alpha
    
    ./configure --with-charset=euc_kr --prefix=/usr/local/mysql
    
    make
    make install
    
    ./scripts/mysql_install_db (óÀ½ Çѹø)
    ./bin/safe_mysqld &
        

  • Zend ¿ÉƼ¸¶ÀÌÀú

    cd ZendOptimizer-Beta2-Linux-glibc2.1
    mkdir /usr/local/Zend/
    mkdir /usr/local/Zend/lib
    cp ZendOptimizer.so /usr/local/Zend/lib
        

  • Apache

    cd apache_1.3.12
    ./configure --prefix=/usr/local/apache
        

  • Php

    cd ../php-4.0.1
    ./configure --with-mysql --with-oci8=/oracle/app/oracle/product/8.1.5/ -- with-apache=../apache_1.3.12 --enable-track-vars --disable-debug --enable-sigchild
    
    make
    make install
        

  • Apache

    cd ../apache_1.3.12
    ./configure --prefix=/usr/local/apache --activate-module=src/modules/php4/libphp4.a
    make
    make install
        

  • ¼öÁ¤ Çϱâ

    /usr/local/apache/conf/httpd.confÈ­ÀÏÀ» ´ÙÀ½°ú °°ÀÌ ÆíÁýÀ» ÇÕ´Ï´Ù.

    AddType application/x-httpd-php .php .php3 .ph(È®ÀåÀÚ)
        

  • ¿¹Á¦

    index.php
    <?
    	phpinfo();
    ?>
        

  • /usr/local/lib/php.ini
    zend_optimizer.optimization_level=1
    zend_extension="/usr/local/Zend/lib/ZendOptimizer.so"
        


3. Apache

  1. CGI »ç¿ëÇϱâ

    apache ÀÇ ¼³Á¤ È­ÀÏÀÎ httpd.conf È­ÀÏÀ» ¼öÁ¤ÇÑ´Ù.

    CGI¸¦ »ç¿ëÇÒ µð·ºÅ丮 : /home/USER/public_html/cgi-bin

    ScriptAlias ¸¦ ¼³Á¤ÇÕ´Ï´Ù.

    ServerName www.formail.com 
    ServerAdmin USER@formail.org.com 
    ScriptAlias /cgi-bin/ /home/USER/public_html/cgi-bin/ 
           

  2. html ¹®¼­ µð·ºÅ丮 ¼³Á¤

    ¾ÆÆÄÄ¡ ¼³Á¤ È­Àϵé '/etc/httpd/conf/httpd.conf' , 'access.conf', 'srm,conf' ÀÔ´Ï´Ù.

    ÇÏÁö¸¸, httpd.conf¿¡¼­ ´ëºÎºÐÀÇ ¼³Á¤ÀÌ °¡´ÉÇÏ´Ù.

    UserDir public_html <-- º¸Åë ÀÌ·¸°Ô µÇ¾î ÀÖÀ» °Ì´Ï´Ù.

    ±×¸®°í°èÁ¤À» Ãß°¡ ÇϽøé

    ¿¹¸¦µé¾î abc¶ó´Â °èÁ¤À» Ãß°¡ Çß´Ù¸é

    http://µµ¸ÞÀÎ/~abc ÀÌ·¸°Ô µË´Ï´Ù.

  3. Url ¼³Á¤

    http://µµ¸ÞÀÎ/~abc --> http://µµ¸ÞÀÎ/abc

    srm.conf È­ÀÏÀ» ¼öÁ¤À» ÇÑ´Ù. ´ÙÀ½À» Ãß°¡ÇÑ´Ù.

    Alias /abc /home/abc/public_html

    ¾ÆÆÄÄ¡¸¦ ´Ù½Ã ½ÇÇà ½ÃŲ´Ù.

    httpd restart or apachectl restart

  4. httpd.conf ¿¹Á¦

    # ¾ÆÆÄÄ¡ ¼­¹ö¸¦ ¼³Ä¡ÇÏ°í ³ª¼­, localhost ¸¦ ÇÏ¸é µðÆúÆ®·Î ³ª¿À´Â ¹®¼­°¡ ÀÖ´Â µð·ºÅ丮ÀÔ´Ï´Ù.
    
    DocumentRoot "/home/httpd/kedu" # ¼Õ´ëÁö ¸»°í µðÆú·Î ±×³É ³ªµÓ´Ï´Ù.
    
    
    
    #ÆÞÀ» »ç¿ëÇÒ¶§ CGI¸¦ »ç¿ëÇÒ¶§´Â ´ÙÀ½°ú °°ÀÌ ¼³Á¤À» ÇØÁÖ¾î¾ß ÇÕ´Ï´Ù.
    <Directory />
        Options FollowSymLinks ExecCGI
        AllowOverride None
    </Directory>
    
    #
    # Note that from this point forward you must specifically allow
    # particular features to be enabled - so if something's not working as
    # you might expect, make sure that you have specifically enabled it
    # below.
    #
    
    #
    # This should be changed to whatever you set DocumentRoot to.
    #
    <Directory "/usr/local/httpd/htdocs">  # ¼Õ´ëÁö ¸»°í µðÆú·Î ±×³É ³ªµÓ´Ï´Ù.
    
    #
    # This may also be "None", "All", or any combination of "Indexes",
    # "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    
    #ÀÌ°ÍÀº ´ÙÀ½°ú °°ÀÌ ¼³Á¤À» ÇØÁÝ´Ï´Ù.
        Options Indexes FollowSymLinks Includes ExecCGI
    
    #
    # This controls which options the .htaccess files in directories can
    # override. Can also be "All", or any combination of "Options", "FileInfo", 
    # "AuthConfig", and "Limit"
    #
        AllowOverride None   # Åë°ú
    
    #
    # Controls who can get stuff from this server.
    #
        Order allow,deny # ¿ª½Ã Åë°ú
        Allow from all   # ¼Õ´ëÁö ¸»°Í
    </Directory>   #  ¼Õ´ëÁö ¸»°í Åë°ú
    
    
    
    # »ç¿ëÀÚ °èÁ¤À» ¸¸µé°í ³ª¼­ À¯ÀúÀÇ index.htm ÀÌ ½ÇÇàµÇ´Â µð·ºÅ丮
    UserDir public_html
    
    
    
    #ºê¶ó¿ìÀú¸¦ ½ÇÇà ÇÒ¶§ ±âº»ÀûÀ¸·Î ÀÐ¾î µéÀÌ´Â È­ÀÏÀ» ¼³Á¤ÇÏ´Â °÷ÀÔ´Ï´Ù.
    
    DirectoryIndex index.htm index.html index.cgi index.php index.php3 
    
    
    # ÆÞÀ» »ç¿ëÇÒ¶§ CGI ¸¦ »ç¿ëÇÒ¶§ ´ÙÀ½°ú °°ÀÌ ¼³Á¤À» ÇÕ´Ï´Ù.
    AccessFileName .htaccess
    
    <Files .htaccess>
        Order allow,deny
        Deny from all
    </Files>
    
    #php ¸¦ »ç¿ëÇÒ¶§´Â ´ÙÀ½°ú °°ÀÌ ¼³Á¤À» ÇØÁÝ´Ï´Ù.
    AddType application/x-httpd-php .php3
    AddType application/x-httpd-php-source .phps
    
    AddType application/x-tar .tgz
    
    
    #ÆÞ CGI¸¦ »ç¿ëÇÒ¶§´Â ´ÙÀ½°ú °°ÀÌ ¼³Á¤À» ÇØÁÝ´Ï´Ù.
    AddHandler cgi-script .cgi
           


4. Html

´Ù¸¥ »çÀÌÆ®·Î ³Ñ¾î°¡±â

<html>
<body>

<meta http-equiv='Refresh' content='0; URL=http://formail.org'>

</body>
</html>
  


5. Perl

5.1. ÆÞ »ç¿ëÇϱâ À§ÇÑ apache, mysql ¼³Á¤

  1. ¾ÆÆÄÄ¡ ¼³Á¤

    ÆÞÀÌ ¼³Ä¡ µÇ¾î ÀÖ³ª Çѹø º¾´Ï´Ù.

    # which perl

    ¾ÆÆÄÄ¡ ¼³Á¤µð·ºÅ丮 (/www/conf/httpd.conf)ÀÇ ´ÙÀ½ ³»¿ëÀÌ ¾øÀ¸¸é Ãß°¡¸¦ ÇÕ´Ï´Ù.

    AddHandler cgi-script .cgi 
    
    ScriptAlias /cgi-bin/ "/www/cgi-bin/" 
         
    AllowOverride None 
    Options None 
    Order allow,deny 
    Allow from all 
            

  2. 1) ÆÞ ¸ðµâ ¼³Ä¡

    Perl `DBD'/`DBI' client code ´Â ÃֽŠ¾ÈÁ¤ ¹öÀüÀ» »ç¿ëÇÑ´Ù.

    Perl °ü·ÃÇÁ·Î±×·¥ µÎ°¡Áö(¼¼°¡Áö)¸¦ ´Ù¿î·ÎµåÇÑ´Ù.

    http://www.cpan.org/modules/01modules.index.html

    Msql-Mysql-modules-1.2204.tar.gz

    DBI-1.13.tar.gz

    Data-Dump-0.03.tar.gz

    ('Data-Dumper'), 'DBI', 'Msql-Mysql-modules' À» ¼ø¼­´ë·Î ¼³Ä¡ÇÑ´Ù.

    2) ¿ì¼± ¾ÐÃàµÈ ÆÐÅ°Áö¸¦ Ǭ´Ù.

    shell> tar xzvf DBI-VERSION.tar.gz 
    shell> tar xzvf Msql-Mysql-modules-VERSION.tar.gz 
           

    3) »ý¼ºµÈ µð·ºÅ丮·Î À̵¿

    shell> cd DBI-VERSION 
           

    4. ÄÄÆÄÀÏ ÇÏ°í ¼³Ä¡

    shell> perl Makefile.PL 
    shell> make 
    shell> make test( Âü°í) 
    shell> make install 
           

    5) Å×½ºÆ®

    Âü°í·Î make test. ¸ðµç ¸ðµâÀ» °ËÁõÇϱ⠶§¹®ÀÌ´Ù.

    6) ³ª¸ÓÁöÁö µÎ°³ ÆÐÅ°Áö ¼³Ä¡

    ³ª¸ÓÁö 'Msql-Mysql-modules'¸¦ À§¿Í °°Àº ¹æ¹ýÀ¸·Î ¼³Ä¡ÇÑ´Ù.

  3. Å×½ºÆ®

    1) /www/cgi-bin/datedisp.cgi ÀÌ È­ÀÏÀ» vi ·Î ÆíÁýÇÑ´Ù.

     
    #! /usr/bin/perl 
    print "Content-type: text/html"; 
    
    $date = `date`; 
         
    print ("Today is $date"); 
           

    2) ±ÇÇÑÀ» ¹Ù²Ù¾î ÁØ´Ù.

    chmod 755 datedisp.cgi 
           

    3) /www/cgi-bin µð·ºÅ丮¿¡¼­ ½ÇÇàÀ» Çغ»´Ù.

     
    ./datedisp.cgi 
    or 
    perl datedisp.cgi 
           

    4) ºê¶ó¿ìÀú¿¡¼­ ´ÙÀ½À» ½ÇÇàÇÕ´Ï´Ù.

     
    http://localhost/cgi-bin/datedisp.cgi
            


5.2. µð·ºÅ丮, È­ÀÏ ¸¸µé±â

µð·ºÅ丮, È­ÀÏ ¸¸µé±â

#!/usr/bin/perl 

use Mysql; 

$dbh = Mysql->connect("","dbname","user","password"); 

print "Content-type: text/html"; 

mkdir('aaa/bbb' , 0777) or die print "µð·ºÅ丮¸¦ ¸¸µé¼ö ¾ø½À´Ï´Ù. ÀÌ¹Ì ¸¸µé¾î Á³½À´Ï´Ù.<br>"; 
print "¿À°ÔÀÌ ¿À°ÔÀÌ"; 

&printf_file("aaa/bbb/test.htm"); 

exit; 

sub print_file{ 
my ($filename) = @_; 
      
$imsi; 
$top="<div align=left><table border=0 cellpadding=5><tr><td valign=top><p align=left><font face=±¼¸² size=2>";

$bottom="</font></td></tr></table></div>"; 
          
$parse{content} =~ s//<br>/g; 
                 
$imsi = $top; 
$imsi.= "¾È³çÇϼ¼¿ä. >(///)< µå¼¼¿ä."; 
$imsi.= $bottom; 
          
open(fh,">$filename"); 
print fh $imsi; 

close(fh); 
}
  


5.3. ½Ã°£ Ãâ·Â¹× Å×ÀÌºí ³»¿ë Ãâ·Â

  1. Mysql ³»¿ë

    mysql> select * from test; 
    +------+--------+------+-------------+ 
    | id | name | age | tel | 
    +------+--------+------+-------------+ 
    | 1 | ±è¿ëÀÏ | 29 | 02-825-xxxx | 
    +------+--------+------+-------------+ 
    1 row in set (0.03 sec) 
          

  2. ¼Ò½º

    #!/usr/bin/perl 
    
    print "Content-type:text/html"; #À¥¿¡¼­ htmlÀ» º¼¼ö ÀÖ°Ô ÇØÁØ´Ù. 
    
    useMysql; #mysqlÀ» »ç¿ëÇÑ´Ù. 
    
    $dbh=Mysql->connect("","kbc","",""); #db¿Í ÆÞÀ» ¿¬°áÇÑ´Ù. 
    
    #½Ã°£ °ªÀ» ¾ò¾î ³½´Ù. 
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); 
    
    #Ãâ·ÂÇÒ ÆûÀ» ÀÛ¼ºÇÑ´Ù. 
    $date = sprintf("%d-%d-%d",$year += 1900, $mon+1, $mday); 
    
    print $date, " "; #Ãâ·ÂÀ» ÇÑ´Ù. 
    
    #print '$curdate()'; #°£´ÜÈ÷ ½Ã°£À» ³ªÅ¸³»´Â ¹æ¹ý 
    
    $query_string = "select * from test"; # ÁúÀǸ¦ º¯¼ö¿¡ ÀúÀåÇÑ´Ù. 
    $sth=$dbh->query($query_string); #º¯¼ö¸¦ ½ÇÇàÇÑ´Ù. 
    
    print $sth->fetchrow_array, " "; # Ãâ·ÂÀ» ÇØÁØ´Ù.
           


5.4. À̸§À» ÀÔ·Â¹Þ¾Æ mysql¿¡ ÀúÀåÇÏ°í Ãâ·ÂÇϱâ

  1. Sql À» ÀÛ¼ºÇÑ´Ù.

     create table test ( 
       no int default '0' not null auto_increment, 
       name char(10), 
       regdate date, 
       PRIMARY KEY(no) 
     ); 
           

  2. name_input.htm À» ÀÛ¼ºÇÑ´Ù.

    <form name="form" method="get" action="/cgi-bin/write_db.cgi">
    <inputtype="text" name="name" size="10"> 
    <input type="submit" name="ok" value="º¸³»±â"> 
    </form>
           

  3. cgi È­ÀÏÀ» ÀÛ¼ºÇÑ´Ù.

    #!/usr/bin/perl #À̹®¼­´Â ÆÞ¹®¼­ ÀÓÀ» ³ªÅ¸³»ÁØ´Ù. 
    
    %parse = &parse_input; # form, inputÀ» °¡´ÉÇϵµ·Ï Á¤ÀǸ¦ ÇÑ´Ù. 
    
    print "Content-type:text/html"; # htmlÀ» »ç¿ë°¡´ÉÇϵµ·Ï ÇÑ´Ù. 
    
    print "ÀÔ·Â µÇ¾ú½À´Ï´Ù. <br>"; 
    
    use Mysql; #Mysql À» Á¤ÀÇ ÇØÁØ´Ù. 
    
    $dbh=Mysql->connect("","kedu","root",""); #MysqlÀ» ÆÞ¿¡¼­ »ç¿ë°¡´ÉÇϵµ·Ï ¿¬°á ½ÃÄÑÁØ´Ù. connect("", "DBÀ̸§", "»ç¿ëÀÚ", "ºñ¹Ð¹øÈ£")
    
    $query_string = "insert into test values('','$parse{name}',curdate())"; # À̸§°ú ½Ã°£À» º¯¼ö¿¡ ÀúÀåÇÑ´Ù. 
    
    $sth=$dbh->query($query_string); # ½ÇÇàÇÑ´Ù. 
    
    $query_string = "select * from test"; # Å×ÀÌºí ³»¿ëÀ» º¯¼ö¿¡ ÀúÀåÇÑ´Ù. 
    $sth=$dbh->query($query_string); # ½ÇÇàÀ» ÇÑ´Ù. 
    
    while($row = $sth->fetchrow_arrayref) 
    { # Å×À̺íÀÇ ¸¶Á÷¸· ·¹ÄÚµå ±îÁö 
      print "$row->[0] $row->[1] $row->[2]<br>"; # Å×ÀÌºí ³»¿ëÀ» Ãâ·Â ÇÑ´Ù. 
    } 
    
    exit; # ºÐ ¹®¼­(ÆÞ)ÀÇ ³¡ÀÓÀ» ³ªÅ¸³» ÁØ´Ù. ÀÌÇÏ ÇÔ¼ö¸¦ Á¤ÀÇ ÇÑ´Ù. 
    # ¹ØÀÇ ÇÔ¼ö´Â ÃæºÐÇÑ ÇнÀÈÄ ¼öÁ¤ÇÏ°í, Ãʺ¸ÀÚ´Â ±×³É ±×·±°¡ º¸´Ù »ý°¢ÇÏ°í ³Ñ¾î°£´Ù. 
    
    sub parse_input 
    { 
      my ($buffer,@parse,%parse,$key,$value); 
    
      if($ENV{'REQUEST_METHOD'} eq "GET")
      { 
        @parse = split(/&/,$ENV{'QUERY_STRING'}); 
      } 
      else { 
        read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); 
        @parse = split(/&/,$buffer); 
      } 
      foreach (@parse) 
      { 
        $_=~ tr/+/ /; 
        $_ =~ s/%([dA-Fa-f][dA-Fa-f])/pack("C",hex($1))/eg; 
        ($key,$value) = split(/=/,$_); 
        $parse{$key} = $value; 
      } 
      return %parse; 
    } 
           


5.5. ÀÔ·Â ¹Þ´Â ºÎºÐÀ» üũ Çϱâ

  1. Sql ÀÛ¼º ( mysql DBNAME < test.tbl )

    create table test ( 
      no int default '0' not null auto_increment, 
      id char(10), 
      name char(10), 
      pw char(8), 
      regdate date, 
      regtime time, 
      PRIMARY KEY(no) 
    ); 
           

  2. check_input.htm ÀÛ¼º

    <html> 
    <body> 
    
    <table> 
    
      <form name="form" method="post" action=/cgi-bin/access_db.cgi> 
      <tr>
        <td>¾ÆÀ̵ð </td> 
        <td><input name=id size=10> <br></td>
      </tr> 
      <tr>
        <td>ÀÌ ¸§ </td> 
        <td><input name=name size=10> <br></td></tr> 
      <tr> 
        <td>ºñ¹Ð¹øÈ£</td> 
        <td><input name=pw size=10 type=password> <br></td></tr> 
      <tr> 
        <td>ºñ¹Ð¹øȣȮÀÎ</td> 
        <td><input name=pw2 size=10 type=password> </td></tr></table> 
    
      <input type="submit" value="º¸³»±â"> 
      </form> 
    
    </table> 
    </body> 
    </html> 
           

  3. access_db.cgi ÀÛ¼º(ÀÛ¼ºÈÄ 755 access_db.cgi ¸¦ ½ÇÇàÇؼ­ ½ÇÇà¸ðµå·Î ¹Ù²Û´Ù.)

    #!/usr/bin/perl 
    
    %parse = &parse_input; 
    
    use Mysql; 
    
    $dbh = Mysql->connect("","kedu","root",""); 
    
    print "Content-type:text/html"; 
    
    if($parse{id} eq ""){ 
      print "¾ÆÀ̵𸦠ÀÔ·ÂÇÏÁö ¾Ê¾Ò½À´Ï´Ù.<br>"; 
      print "¾ÆÀ̵𸦠ÀÔ·Â ÇØÁÖ¼¼¿ä.<br>"; 
    } 
    elsif($parse{name} eq "" ){ 
      print "À̸§À» ÀÔ·ÂÇÏÁö ¾Ê¾Ò½À´Ï´Ù.<br>"; 
      print "À̸§À» ÀÔ·Â ÇØÁÖ¼¼¿ä.<br>"; 
    } 
    elsif($parse{pw} eq "" ){ 
      print "ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏÁö ¾Ê¾Ò½À´Ï´Ù.<br>"; 
      print "ºñ¹Ð¹øÈ£¸¦ ÀÔ·Â ÇØÁÖ¼¼¿ä.<br>"; 
    } 
    elsif($parse{pw2} eq "" ){ 
      print "ºñ¹Ð¹øȣȮÀÎÀ» ÀÔ·ÂÇÏÁö ¾Ê¾Ò½À´Ï´Ù.<br>"; 
      print "ºñ¹Ð¹øȣȮÀÎÀ»ÀÔ·Â ÇØÁÖ¼¼¿ä.<br>"; 
    } 
    elsif(($parse{id} =~ /^d/) || ($parse{name} =~ /^d/)) { 
      print "ù¹ø° ±ÛÂ¥°¡ ¼ýÀÚ·Î µÇ¾î ÀÖ½À´Ï´Ù.<br>"; 
      print "ù¹ø°±ÛÂ¥¸¦ ¹®ÀÚ·Î ¹Ù²Ù¾î ÁÖ¼¼¿ä.<br>"; 
    } 
    elsif(&registered_id($parse{id})) { 
      print "ÀÌ¹Ì ÀÖ´Â ¾ÆÀ̵ð ÀÔ´Ï´Ù.<br>"; 
      print "´Ù¸¥ ¾ÆÀ̵𸦠ÀÔ·Â ÇØÁÖ¼¼¿ä.<br>"; 
    } 
    elsif($parse{pw} ne $parse{pw2}) { 
      print "ºñ¹Ð¹øÈ£°¡ °°Áö ¾Ê½À´Ï´Ù. <br>"; 
      print "ºñ¹Ð¹øÈ£¸¦ ´Ù½Ã ÀÔ·Â ÇØÁÖ¼¼¿ä. <br>"; 
    } 
    else { 
      print$parse{id}, "°¡ ÀÔ·Â µÇ¾ú½À´Ï´Ù.<br>"; 
      $query_string = "insert into test values('','$parse{id}','$parse{name}','$parse{pw}', curdate(), curtime())"; 
      my $sth=$dbh->query($query_string); 
    } 
    
    $query_string = "select * from test"; 
    
    $sth=$dbh->query($query_string); 
    
    while($row = $sth->fetchrow_arrayref)
    { 
      print "$row->[0] $row->[1] $row->[2] $row->[3] $row->[4] $row->[5]<br>"; 
    } 
    
    exit; 
    
    sub registered_id 
    { 
      my ($id) = @_; 
      my ($query_string) = "select id from test where id = '$id'"; 
      my ($sth) = $dbh->query($query_string); 
      if($sth -> numrows eq "1") 
      { 
        return 1; 
      } 
      else 
      { 
        return 0; 
      } 
    } 
    
    sub parse_input 
    { 
      my ($buffer,@parse,%parse,$key,$value); 
      if($ENV{'REQUEST_METHOD'} eq "GET")
      { 
        @parse = split(/&/,$ENV{'QUERY_STRING'}); 
      } 
      else 
      { 
        read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); 
        @parse = split(/&/,$buffer); 
      } 
      foreach (@parse) 
      { 
        $_ =~ tr/+/ /; 
        $_ =~ s/%([dA-Fa-f][dA-Fa-f])/pack("C",hex($1))/eg; 
        ($key,$value) = split(/=/,$_); 
        $parse{$key} = $value; 
      } 
      return %parse; 
    } 
           


6. Php

6.1. ³ëÇÁ·¹ÀÓ ¸¸µå´Â¹ý

¸Ó¸®´Ü°ú ¹Ù´Ú¿¡ µé¾î°¥ È­ÀÏÀ» ÀÛ¼ºÇÏ°í ³ª¼­ º» È­ÀÏ¿¡¼­ ºÒ·¯¼­ »ç¿ëÇÏ¸é µÈ´Ù.

main.php

 
<?php 

include("include/header.ph"); 

print_html("main_htm/top.htm"); 

echo("<br><br>º»¹® ³»¿ëÀÌ µé¾î°¡´Â °÷ÀÔ´Ï´Ù.<br>"); 
echo("³»¿ëÀº º°°Å ¾ø½À´Ï´Ù.<br>"); 
echo("ÇÁ·¹ÀÓÀ» ³ª´©Áö ¾Ê°í, º»¹® ³»¿ëÀ» »ç¿ëÇÏ´Â °ÍÀÔ´Ï´Ù.<br>"); 
echo("º»¹®³»¿ëÀ» ¼­ºê ÇÔ¼ö¸¦ ÀÌ¿ëÇؼ­ ¸¸µé¸é µË´Ï´Ù.<br>"); 
echo("´ÙÀ½ ÀÛ¾÷À» À§ÇØ ½¬¿î ³»¿ëÀ» ¾ÆÁÖ ¾î·Æ°Ô Çß½À´Ï´Ù.<br>"); 
echo("À̳»¿ëÀ» Àß ÀÌÇØÇÏ¸é ¿©·¯¸é¿¡¼­ µµ¿òÀÌ µÉ°ÍÀÔ´Ï´Ù.<br>"); 

print_html("main_htm/bottom.htm"); 

?> 
  

include/header.ph

 
<? 
/* ÇѶóÀÎ Ãâ·ÂÇØÁÖ´Â ÇÔ¼ö */ 
function print_html($filename)
{ 
	$fp = fopen( $filename, "r" ); 

	while(!feof($fp)) 
	{ 
		$contents .= fgets($fp, 100); 
	} 
           
  fclose($fp); 
  echo "$contents"; 
} 
?> 

	

main_htm/top.htm

<html> 
<head> 
<title>³ª¶óºñÀÇ ¹æ</title> 
<style TYPE="TEXT/CSS"> 
  A:link {color: blue; text-decoration:none} 
  A:visited {color: navy; text-decoration:none} 
  A:hover {color: red; text-decoration:underline;} 
</style> 
</head> 

<body> 
  <table border="0" width = "600" cellpadding="0" cellspacing="0"> 
    <tr><td width="589" colspan="2" bgcolor="#f9cd8a">³ª¶óºñÀÇ ¹æÀ» ã¾ÆÁּż­ ´ë´ÜÈ÷ °¨»çÇÕ´Ï´Ù.</td></tr> 
    <tr> 
      <tr> 
        <td width = "120" valign="top" colspan="0"> 
          <table width = "120" border="0"> 
            <tr><td width="120" bgcolor="#b5d490"><p> <b><br>ȨÀ¸·Î</b></font></td></tr> 
            <tr><td width="120" bgcolor="#c3f298"><p> <font size="2">³ª¶óºñ ¼Ò°³</font></td></tr> 
            <tr><td width="120" bgcolor="#c3f298"><p> <font size="2">³ª¸®ºñ ¼Ò½Ä</font></td></tr> 
            <tr><td width="120" bgcolor="#c3f298"><p> <font size="2">Windows NT</font></td></tr> 
            <tr><td width="120" bgcolor="#c3f298"><p> <font size="2">½Ã(±è¼Ò¿ù)</font></td> </tr> 
            <tr><td width="120" bgcolor="#c3f298"><p> <font size="2">½Ã(±âŸ)</font></td> </tr> 
            <tr><td width="120" bgcolor="#c3f298"><p> <font size="2">Áú¹®°ú´äº¯</font></td> </tr> 
            <tr><td width="120" bgcolor="#c3f298"><p> <font size="2">´Ù¸¥°÷</font></td> </tr> 
          </table> 
       <td valign="top" align="center" width = "480">  
	

main_htm/bottom.htm

       </td> 
     </tr> 
   <tr> 
     <td colspan="2" align="center" valign="top">Copyright ¨Ï 1999 nalabi.Mail to<a href="mailto:nalabi@hananet.net">webmaster</a></td> 
   </tr> 
  </table> 
</body> 
</html>

  


6.2. À̸§À» ÀÔ·Â¹Þ¾Æ mysql¿¡ ÀúÀåÇÏ°í Ãâ·ÂÇϱâ

  1. Å×À̺í ÀÛ¼º (mysql DBNAME < test.tbl)

    create table test ( 
      no int default '0' not null auto_increment, 
      name char(10), 
      regdate date, 
      PRIMARY KEY(no) 
    );
           

  2. name_input.php ÀÛ¼º

    <html> 
    <body> 
    
    <form name="form" method="get" action="write_db.php3"> 
    <inputtype="text" name="name" size="10"> 
    <input type="submit" name="ok" value="º¸³»±â">
    </form> 
    
    </body>
    </html>
           

  3. write_db.php ÀÛ¼º

    <? 
    // MySQL ¼­¹ö¿¡ ¿¬°áÇÑ´Ù 
    $connect=mysql_connect( "localhost", "root", "") or die( "SQL server¿¡ ¿¬°á ÇÒ¼ö ¾ø½À´Ï´Ù."); 
    
    $tbl_list = mysql_list_tables("kedu"); //µ¥ÀÌŸ º£À̽º¸¦ ¼³Á¤ÇÕ´Ï´Ù. 
       
    $result = mysql_query("insert into test (name) values ('$name')"); 
    $result=mysql_query($result, $connect ); 
    
    $tbl_name="select * from test" ; 
    $result=mysql_query($tbl_name, $connect ); 
    
    $print=mysql_fetch_array($result); //Å×À̺íÀÇ ³»¿ëÀ» °¡Á®¿È 
       
    $rows = mysql_num_rows($result); 
    
    echo("ÀÔ·Â µÇ¾ú½À´Ï´Ù..<br>"); 
    
    for($i=0; $i< $rows;$i++) 
    { 
      echo("$print[name]<br>"); 
      $print=mysql_fetch_array($result); 
    } 
    ?> 
           


6.3. À̸§À» ÀÔ·Â¹Þ¾Æ Ã¼Å©ÇÏ°í mysql¿¡ ÀúÀåÇÏ°í Ãâ·ÂÇϱâ

  1. Å×À̺í ÀÛ¼º ( mysql DBNAME < test.tbl )

    create table test ( 
      no int default '0' not null auto_increment, 
      id char(10), 
      name char(10), 
      pw char(8), 
      regdate date, 
      regtime time, 
      PRIMARY KEY(no) 
    ); 
           

  2. check_input.php ÀÛ¼º

    <html> 
    <body> 
    
    <table> 
    <form name="form" method="post" action=access_db.php3> 
        
       <tr> 
         <td>¾ÆÀ̵ð </td> 
         <td><INPUT name=id size=10> <br></td></tr> 
       <tr> 
         <td>ÀÌ ¸§ </td> 
         <td><INPUT name=name size=10> <br></td></tr> 
       <tr> 
         <td>ºñ¹Ð¹øÈ£</td> 
         <td><INPUT name=pw size=10 type=password> <br></td></tr> 
       <tr> 
         <td>ºñ¹Ð¹øȣȮÀÎ</td> 
         <td><INPUT name=pw2 size=10 type=password> </td></tr></table> 
    
       <input type="submit" value="º¸³»±â"> 
    
    </form> 
    </table> 
    
    </body> 
    </html> 
           

  3. access_db.php ÀÛ¼º

    <? 
    // MySQL ¼­¹ö¿¡ ¿¬°áÇÑ´Ù 
    $connect=mysql_connect( "localhost", "root", "") or die( "SQL server¿¡ ¿¬°á ÇÒ¼ö ¾ø½À´Ï´Ù."); 
    $tbl_list= mysql_list_tables("kedu"); //µ¥ÀÌŸ º£À̽º¸¦ ¼³Á¤ÇÕ´Ï´Ù. 
    
    if($id == "") { 
      echo "¾ÆÀ̵𸦠ÀÔ·Â ÇÏÁö ¾Ê¾Ò½À´Ï´Ù."; 
    } 
    elseif($name == ""){ 
      echo "À̸§À» ÀÔ·Â ÇÏÁö ¾Ê¾Ò½À´Ï´Ù."; 
    } 
    elseif($pw == ""){ 
      print "ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏÁö¾Ê¾Ò½À´Ï´Ù.<br>"; 
      print "ºñ¹Ð¹øÈ£¸¦ ÀÔ·Â ÇØÁÖ¼¼¿ä.<br>"; 
    } 
    elseif($pw2 == ""){ 
      print "ºñ¹Ð¹øȣȮÀÎÀ» ÀÔ·ÂÇÏÁö ¾Ê¾Ò½À´Ï´Ù.<br>"; 
      print "ºñ¹Ð¹øȣȮÀÎÀ» ÀÔ·Â ÇØÁÖ¼¼¿ä.<br>"; 
    } 
    elseif($pw != $pw2) { 
      print "ºñ¹Ð¹øÈ£°¡ °°Áö ¾Ê½À´Ï´Ù. <br>"; 
      print "ºñ¹Ð¹øÈ£¸¦ ´Ù½Ã ÀÔ·Â ÇØÁÖ¼¼¿ä. <br>"; 
    } 
    else { 
      echo "$id°¡ ÀÔ·Â µÇ¾ú½À´Ï´Ù..<br>"; 
    
      $date = date("y-m-d", time()); 
    
      $result = mysql_query("insert into test values ('','$id','$name','$pw','$date','$time')"); 
      $result=mysql_query($result, $connect); 
    
      $tbl_name="select *from test" ; 
      $result=mysql_query($tbl_name, $connect ); 
    
      $print=mysql_fetch_array($result); //Å×À̺íÀÇ ³»¿ëÀ» °¡Á®¿È 
      
      $rows = mysql_num_rows($result); 
    
      for($i=0; $i< $rows;$i++) 
      { 
        echo("$print[id] $print[name] $print[pw] $print[regdate]<br>"); 
        $print=mysql_fetch_array($result); 
      } 
    } 
    ?> 
           


6.4. Å×À̺í Ãâ·Â ÇÁ·Î±×·¥

Å×À̺í Ãâ·Â ÇÁ·Î±×·¥

<? 
// MySQL ¼­¹ö¿¡ ¿¬°áÇÑ´Ù 
$connect=mysql_connect( "localhost", "username", "") or die( "Unabletoconnect to SQL server"); 
//-------------------------------------------------------------------------- 
// »ç¿ë°¡´ÉÇÑ DB ¸ñ·ÏÀ» °Ë»ö 
//-------------------------------------------------------------------------- 
$dblist = mysql_listdbs(); //µ¥ÀÌŸ º£À̽º ¸ñ·ÏÀ» ÀνÄÇÑ´Ù. 
$dbnum=mysql_num_rows($dblist); //µ¥ÀÌŸ º£À̽º °¹¼ö¸¦ º¯¼ö¿¡ ÀúÀåÇÑ´Ù. 

for($i=0; $i < $dbnum; $i++) //µ¥ÀÌŸ º£À̽º °¹¼ö ¸¸Å­ 
{ 
  $dbname[$i] = mysql_dbname($dblist, $i) ; //µ¥ÀÌŸ º£À̽º ¸ñ·Ï À̸§À» º¯¼ö¿¡ ÀúÀåÇÑ´Ù. 
} 
echo "µ¥ÀÌŸ º£À̽º °Ë»ö ³»¿ë <br>"; 
for($i=0; $i < count($dbname); $i++)
{ //µ¥ÀÌŸ º£À̽º °¹¼ö ¸¸Å­ 
  echo "$dbname[$i] <br>"; // µ¥ÀÌŸ º£À̽º À̸§À» À¥¿¡ ³ªÅ¸³»ÁØ´Ù. 
} 

//-------------------------------------------------------- 
// »ç¿ë°¡´ÉÇÑ Å×ÀÌºí ¸ñ·ÏÀ» °Ë»ö 
//-------------------------------------------------------- 

$tbl_list = mysql_list_tables("board"); //µ¥ÀÌŸ º£À̽º¸¦ ¼³Á¤ÇÕ´Ï´Ù. 
$tbl_num=mysql_num_rows($tbl_list); // Å×ÀÌºí °¹¼ö¸¦ º¯¼ö¿¡ ÀúÀåÇÕ´Ï´Ù. 

echo "<br>µ¥ÀÌŸ Å×ÀÌºí °Ë»ö ³»¿ë--> Å×À̺í¸í,·¹ÄÚµå¼ö<br>"; 
for($i=0; $i < $tbl_num; $i++) //Å×ÀÌºí °¹¼ö ¸¸Å­ 
{ 
  $tbl_name[$i] = mysql_tablename($tbl_list,$i) ; // Å×À̺í À̸§À» º¯¼ö¿¡ ÀúÀå 
  $result[$i] = mysql_query( "SELECT * FROM $tbl_name[$i]"); //Å×À̺íÀÇ ³»¿ëÀ» º¯¼ö¿¡ ÀúÀå 
  $rows[$i] = mysql_num_rows($result[$i]); // Å×À̺íÀÇ ·¹ÄÚµå ¼ö¸¦º¯¼ö¿¡ ÀúÀå 
  echo "$tbl_name[$i], $rows[$i], $name <br>"; //Å×À̺íÀÇ À̸§°ú, ·¹ÄÚµå¼ö¸¦ À¥¿¡ Ãâ·Â ÇØÁÝ´Ï´Ù. 
} 

//-------------------------------------------------------------------- 
// »ç¿ë°¡´ÉÇÑ Å×ÀÌºí ³»¿ëÀ» Ãâ·Â
//-------------------------------------------------------------------- 

$tbl_name="select * from test" ; 

$result=mysql_query($tbl_name, $connect ); 
$print=mysql_fetch_array($result); //Å×À̺íÀÇ ³»¿ëÀ» °¡Á®¿È 

echo("<br>Å×ÀÌºí ³»¿ëÀ» È­¸é¿¡ Ãâ·Â ½ÃÄÑ ÁÝ´Ï´Ù.<br>"); 
echo("À̸§, ³ªÀÌ, ÀüÈ­¹øÈ£ºÎ, ÁÖ¼Ò<br>"); 
echo("$print[name], $print[age], $print[tel], $print[addr]<br>"); 
   

//------------------------------------------------------------------------------- 
// »ç¿ë°¡´ÉÇÑ Å×ÀÌºí ³»¿ëÀ» Àüü Ãâ·Â
//------------------------------------------------------------------------------- 
$que_bbs="select * from test" ; 

$result=mysql_query($que_bbs,$connect ); 
$print=mysql_fetch_array($result); 
$rows = mysql_num_rows($result); 
echo("<br>Å×ÀÌºí ³»¿ë Àüü¸¦ Ãâ·Â ½ÃÄÑ ÁÝ´Ï´Ù.<br>"); 
echo("À̸§, ³ªÀÌ, ÀüÈ­¹øÈ£ºÎ, ÁÖ¼Ò<br>"); 
for($i=0; $i < $rows; $i++) 
{ 
  echo("$print[name], $print[age], $print[tel], $print[addr]<br>"); 
  $print=mysql_fetch_array($result); 
} 
?>
  


6.5. mysql_fetch_array ¿¹Á¦

mysql_free_result ¸¦ Çؼ­ ¸Þ¸ð¸®¸¦ Ç®¾î ÁØ´Ù.

<?

mysql_connect($db_server, $db_user, $db_pass);

$result = mysql_db_query("$db_name","select * from $table_name");

while($row = mysql_fetch_array($result)) 
{
  echo $row["no"];
  echo $row["name"];
  echo " ";
}

mysql_free_result($result);
?>
    


6.6. À̹ÌÁö È­ÀÏ Ãâ·Â

<?
Header("Content-type: image/gif");

$file = "test.gif";

$size = 4096;
if (!($fp = fopen($file, "r"))) 
{ 
  die("could not open input"); 
  exit; 
} 

while ($data = fread($fp,$size)) 
{ 
  print($data); 
}	
?>
    


6.7. ´Þ·Â ¿¹Á¦

´Þ·Â ¿¹Á¦

<?

// º¯¼ö°ª ¼³Á¤
$date=01; 
$day=01; 
$off=0; 

//³âµµ ´Þ ¼³Á¤
$year = '2000'; 
$month = '01'; 


/*  Figure out how many days are in this month  */ 
while (checkdate($month,$date,$year)): 
    $date++; 
endwhile; 

// ¸Þ´º Ç¥½ÃÇϱâ
echo "<table width='420' ><tr><td align = center>$year ³â $month ¿ù</td></tr></table>";
echo "<table border='1'  width='420'><tr>"; 
echo "<td><b><font face='µ¸À½'>¿ù</font></b></td>"; 
echo "<td><b><font face='µ¸À½'>È­</font></b></td>"; 
echo "<td><b><font face='µ¸À½'>¼ö</font></b></td>"; 
echo "<td><b><font face='µ¸À½'>¸ñ</font></b></td>"; 
echo "<td><b><font face='µ¸À½'>±Ý</font></b></td>"; 
echo "<td><b><font face='µ¸À½'>Åä</font></b></td>"; 
echo "<td><b><font face='µ¸À½'>ÀÏ</font></b></td>"; 
echo "<tr>"; 

//·çÇÁ µ¹¸®±â
while ($day<$date): 

/*  Figure what day of the week the first falls on and set the number of preceding and trailing cells accordingly  */ 
if ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Sunday') 
{ 
    echo "<td>$day</td>"; 
    $off = '01'; 
}  
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==  'Monday') 
{ 
    echo "<td></td><td>$day</td>"; 
    $off= '02'; 
}  
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==  'Tuesday') 
{ 
    echo "<td></td><td></td><td>$day</td>";
    $off= '03'; 
}  
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==  'Wednesday') 
{ 
    echo "<td></td><td></td><td></td><td>$day</td>"; 
    $off= '04'; 
}  
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==  'Thursday') 
{ 
    echo "<td></td><td></td><td></td><td></td><td>$day</td>"; 
    $off= '05'; 
}  
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==  'Friday') 
{ 
    echo "<td></td><td></td><td></td><td></td><td></td><td>$day</td>"; 
    $off= '06'; 
}  
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==  'Saturday') 
{ 
    echo "<td></td><td></td><td></td><td></td><td></td><td></td><td>$day</td>"; 
    $off= '07'; 
}  
else 
{ 
    echo "<td>$day</td>"; 
} 

//ÀÏ Áõ°¡ ½ÃÅ°±â
$day++; 
$off++; 

if ($off>7) 
{ 
    echo "</tr><tr>"; 
    $off='01'; 
} else 
{ 
    echo ""; 
} 

endwhile; 

echo "</table>"; 

?>
    


6.8. ¿øÇÏ´Â ¹®ÀÚ¿­ °Ë»ö(ereg)

¾î¶² ¹®ÀÚ¿­ Áß¿¡¼­ 000 À̶ó´Â ¹®ÀÚ¿­ÀÇ ·¹Äڵ带 ã¾Æ ³»±â

Ç¥Çö :

int ereg(string pattern, string string, array [regs]);

»ç¿ë¹ý :

ereg(ãÀ» ÆÐÅÏ, °Ë»çÇÒ ¹®ÀÚ¿­, °á°ú ¹è¿­);

¿¹Á¦ :

ereg("([0]{3})", $hash[code], $regs)

°¢°¢ÀÇ ÆÐÅÏÀº ()·Î Á¤ÀǸ¦ ÇÕ´Ï´Ù.

([0]{3})´Â 0ÀÇ°¹¼ö°¡ 3°³·Î ³ª¿Í¾ßÇÑ´Ù´Â ÀǹÌÀÌ´Ù.

([0]{2, 3}) 0ÀÇ °¹¼ö°¡ 2°³ ȤÀº 3°³¸¦ ÀǹÌ

([0-9]{2, 3}) 0¿¡¼­ 9±îÁöÀÇ ¼ýÀÚ°¡ 2ÀÚ¸® ȤÀº 3ÀÚ¸®¸¦ ÀǹÌ

    
<?

$sth = mysql_query("select * from kangsa_type order by code");

while($hash = mysql_fetch_array($sth)) 
{ 
  if(ereg("([0]{3})", $hash[code], $regs)) 
  {
    print "$hash[typename]";
  }
}

?>
    


6.9. ÀÎÁõ ¿¹Á¦

  1. auth.sql À» ¸ÕÀú ÀÛ¼ºÀ»ÇÑ´Ù.

    # MySQL dump 6.6
    #
    # Host: localhost    Database: myhome
    #--------------------------------------------------------
    # Server version    3.23.8-alpha
    
    #
    # Table structure for table 'auth'
    #
    CREATE TABLE auth (
      id char(10) DEFAULT '' NOT NULL,
      passwd char(10),
      name char(10),
      level int(11),
      PRIMARY KEY (id)
    );
    
    #
    # Dumping data for table 'auth'
    #
    
    INSERT INTO auth VALUES ('nalabi','xxxx','±è¿ëÀÏ',1);
            

  2. auth.ph ÀÎÁõÇÏ´Â ºÎºÐÀ» ÀÛ¼ºÇÑ´Ù.

    <?php 
    
    cfunction authenticate() 
    {
      Header( "HTTP/1.0 401 Unauthorized"); 
      $title= "Invalid Login";
    ?> 
      ¾ÆÀ̵ð¿Í ¾ÏÈ£°¡ ÇÊ¿äÇÕ´Ï´Ù! 
    <?php  exit;
    } 
    
    if(!isset($PHP_AUTH_USER)) 
    { 
      authenticate(); 
    } else 
    { 
      mysql_pconnect( 'localhost', 'root', '') or die( "Unable to connect to SQL server");  // MySQL ¼­¹ö Á¢¼Ó 
            
      mysql_select_db( "test") or die( "Unable to select database");              // DB ¼±Åà 
            
      $result = mysql_query( "select name , level from auth where id='$PHP_AUTH_USER'  and passwd='$PHP_AUTH_PW' ");
            
      if(!mysql_num_rows($result)) 
      {  
        authenticate(); 
      } 
      else  
      { 
        $userinfo = mysql_fetch_array($result); 
      } 
    } 
    ?> 
            

  3. test.php ÇÁ·Î±×·¥ Çϴµ¥¼­ ÀÎÁõÇÏ´Â ºÎºÐÀ» Àû¿ëÇÑ´Ù.

    <?
    
    include ("auth.ph");
    
    echo("¾î¼­ ¿À½Ê½Ã¿ä.");
    
    ?>
            


6.10. Ä¿³Î ¹öÀü ³ªÅ¸³»ÁÖ´Â ÇÔ¼ö

kernel.php

<?
function kernel() 
{
  $label = array("¾ÈÁ¤¹öÀü","°³¹ß¹öÀü","¾ËÆĹöÀü");
  $cmd = "/usr/bin/finger @ftp.kernel.org| cut -c59-66 | sed -e '/^$/d'";
  exec($cmd,$array,$rtn);

  for($i=0; $i < count($array); $i++) 
  {
    list($v1, $v2, $v3)  = split('[/.-]' , $array[$i]);
    $version = "v".$v1.".".$v2."/linux-".$array[$i].".tar.gz";
		
    $label[$i] = "<a href = ftp://ftp.kernel.org/pub/linux/kernel/".$version.">".$label[$i]." : ".$array[$i]."</a>";
  }

  return $label;
}

$label = kernel();

echo("$label[0] <br> $label[1] <br> $label[2]");
	
?>
    


6.11. µµ¸ÞÀΠǥ½Ã ÇÔ¼ö

whois ÇÁ·Î±×·¥ÀÌ ±ò·Á ÀÖ¾î¾ß ÇÕ´Ï´Ù.

rpm -qa | grep whois

 
    whois-1.0.10-1
    

ÇÁ·Î±×·¥

 
<?
function domain($string) 
{
  $cmd = "whois $string";
  exec($cmd,$array,$rtn);

  for ($i=0; $i < count($array); $i++) 
  { 
    $rstring .= "$array[$i]";
  }
  return $rstring;
}

print domain("formail.org");

?>
    


6.12. ¹®ÀÚ¿­ üũ ÇÔ¼ö ¿¹Á¦(ereg)

¹®ÀÚ¿­¿¡ ¿µ¾î ´ë¼Ò¹®ÀÚ, ¼ýÀÚ¸¸ ¿Àµµ·Ï ÇÏ°Ô ÇÏ´Â ÇÔ¼öÀÔ´Ï´Ù

<?
function check_id($string)
{
  $error_msg = "error";

  if (ereg("[^a-zA-Z0-9]", $string)) 
  {
    $error_msg = $error_msg;
    return $error_msg;
  }
  else 
  {
    return $string;
  }
}

$id1 = "abcd";
$id2 = "ZabCA";
$id3 = "9Zab01";
$id4 = "#ab.c.%";
$id5 = "ÇѱÛ";

$msg = check_id($id1);
print "id1 : $msg";

$msg = check_id($id2);
print "id2 : $msg";

$msg = check_id($id3);
print "id3 : $msg";

$msg = check_id($id4);
print "id4 : $msg";

$msg = check_id($id5);
print "id5 : $msg";
?>
    


6.13. IDüũ ÇØÁÖ´Â ÇÁ·Î±×·¥

  1. sql ¹®

    # MySQL dump 7.2
    #
    # Host: localhost    Database: test
    #--------------------------------------------------------
    # Server version	3.23.11-alpha
    
    #
    # Table structure for table 'login3'
    #
    CREATE TABLE login3 (
      nick char(10)
    );
    
    #
    # Dumping data for table 'login3'
    #
    
    INSERT INTO login3 VALUES ('³ª¶óºñ');
            

  2. test.php

    <?
    function add_error($why, $reason, $nick) 
    {
      print "$reason<br>";
    }
    
    $nick= "³ª¶óºñ";
    
    if (ereg ("[~!@#$%^&*()~|"/'+=-_:;,.<>]", $nick)) 
    { 
      $why="´Ð³×ÀÓ"; 
      $reason="´Ð³×ÀÓ¿¡ Ư¼ö¹®ÀÚ°¡ ÀÖ½À´Ï´Ù."; 
      add_error($why,$reason,$nick); 
      exit; 
    } 
                         
    if(ereg(" ", $nick)) 
    { 
      $why="´Ð³×ÀÓ"; 
      $reason="´Ð³×ÀÓ¿¡ °ø¹éÀÌ ÀÖ½À´Ï´Ù."; 
      add_error($why,$reason,$nick); 
      exit; 
    } 
                         
    if($nick=="") 
    { 
      $head = "´Ð³×ÀÓ"; 
      $mesg = "´Ð³×ÀÓÀÌ ¾ø½À´Ï´Ù."; 
      add_error($head,$mesg,$nick); 
    } 
    
    if(strlen($nick) < 2) 
    { 
      $head = "´Ð³×ÀÓ"; 
      $mesg = "´Ð³×ÀÓÀº Ư¼ö¹®ÀÚ¸¦ Á¦¿ÜÇÑ 2ÀÚÀÌ»óÀ¸·Î ³Ö¾îÁÖ¼¼¿ä."; 
      add_error($head,$mesg,$nick); 
    } 
    
    $server = "localhost";
    $name = "root";
    $passwd = "";
    $dbname = "test";
    
    mysql_connect($server, $name, $passwd);
    mysql_select_db($dbname);
    
    
    $que1 = "select nick from login3 where nick='$nick'"; 
    $result= mysql_query($que1); 
    $current_row = mysql_fetch_row($result); 
                         
    if($current_row[0] == $nick) 
    { 
      $head = "´Ð³×ÀÓ"; 
      $reason = $nick."´ÔÀÌ  ÀÌ¹Ì µî·ÏµÇ¾î ÀÖ½À´Ï´Ù."; 
      add_error($why,$reason,$nick); 
    } 
    else 
    {
    	print $nick;
    }
    ?>
            


6.14. °Ô½Ã¹° ÆäÀÌÁö º¯°æ ¿¹Á¦

  1. sql ¹®

    # MySQL dump 6.4
    #
    # Host: localhost    Database: test
    #--------------------------------------------------------
    # Server version	3.23.5-alpha
    
    #
    # Table structure for table 'login'
    #
    CREATE TABLE login (
      id char(10) DEFAULT '' NOT NULL,
      reg_date char(10),
      nick char(10),
      passwd char(10),
      name char(10),
      user_num int(11),
      address char(10),
      phone char(10),
      email char(10),
      job char(10),
      PRIMARY KEY (id)
    );
    
    #
    # Dumping data for table 'login'
    #
    
    INSERT INTO login VALUES ('nalab1','','aaaa','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nalab2','','bbbb','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nalab3','','cccc','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nalab4','','dddd','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nalab5','','eeee','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nalab6','','ffff','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nalab7','','gggg','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nalab8','','hhhh','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nalab9','','iiii','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nala10','','jjjj','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nala11','','kkkk','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nala12','','llll','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nala13','','mmmm','bbbb','1111',0,'1','cccc','dddd','eeee');
    INSERT INTO login VALUES ('nala14','','nnnn','bbbb','1111',0,'1','cccc','dddd','eeee');
            

  2. test.php

    <?
    
    $server = "localhost";
    $name = "root";
    $passwd = "";
    $dbname = "test";
    
    mysql_connect($server, $name, $passwd);
    mysql_select_db($dbname);
    
    
    $page_scale=3; //ÇÑÆäÁã´ç º¸¿©ÁÙ ¼ýÀÚ ¹øÈ£[1][2][3] 
    $scale=2; // ÇÑÆäÀÌÁã ´ç º¸¿©ÁÙ ¶óÀÎ °³¼ö(·¹ÄÚµå)  
        
    if(!$star){ $star= 0 ;}  // ½ÃÀÛÇÒ ·¹ÄÚµå ¹øÈ£ - 1
        
    $page=floor($star/($scale*$page_scale));  // ÆäÀÌÁö ¼ö ¾ò±â
    
    $que1="select DATE_FORMAT(reg_date,'Y.m.d'), id,nick, passwd ,name , user_num, address, phone,  email, job from login order by reg_date DESC " ; 
    
    $result = mysql_query($que1);
        
    $total = mysql_affected_rows(); //°Ô½Ã¹° ÃÑ ¼ö
        
    $last=floor($total/$scale); //¸¶Áö¸· ¹øÈ£
        
    echo "<font size=-1>Àüü µî·ÏÀÚ : $total ¸í ÀÔ´Ï´Ù."; 
        
    echo "<html><title>ȸ¿ø°ü¸®</title><body bgcolor=ffffff><center><font size=4>ȸ¿ø°ü¸® ÆäÀÌÁö</font>
            <table border=1><tr bgcolor=336699>
              <td align=center><font color=ffffff size=-1>µî·ÏÀÏ</font><td align=center><font color=ffffff size=-1>ID</font></td>
              <td align=center><font color=ffffff size=-1>´Ð³×ÀÓ</font></td>
              <td align=center><font color=ffffff size=-1>ºñ¹Ð¹øÈ£</font></td>
              <td align=center><font color=ffffff size=-1>À̸§</font></td>
              <td align=center><font color=ffffff size=-1>Áֹεî·Ï¹øÈ£</font></td>
              <td align=center><font color=ffffff size=-1>ÁÖ¼Ò</font></td>
              <td align=center><font color=ffffff size=-1>¿¬¶ôó</font></td>
              <td align=center><font color=ffffff size=-1>E-Mail</font></td>
              <td align=center><font color=ffffff size=-1>Á÷¾÷</font></td>
              <td align=center><font color=ffffff size=-1>°ü¸®</font></td></tr>";
    
    if($star) 
    {  
      $n=$total-$star;  
    }
    else  
    {      
      $n=$total;  
    }
    
    for($i=$star ; $i< $star+$scale ; $i++)  //  star ¿¡¼­ scale ±îÁö ¸¸
    {
      if($i< $total ) // Àüü ÀÚ·á °³¼ö±îÁö¸¸ Ãâ·Â 
      { 
        mysql_data_seek($result,$i);
        $row=mysql_fetch_array($result);
                 
        $imsi=$row[5];
                 
        echo"<tr><td align=center><font size=-1>$row[0]</font></td>
               <td align=center><font size=-1>$row[1]</font></td>
               <td align=center><font size=-1>$row[2]</font></td>
               <td align=center><font size=-1>$row[3]</font></td>
               <td align=center><font size=-1>$row[4]</font></td>
               <td align=center><font size=-1>$row[5]</font></td>
               <td align=center><font size=-1>$row[6]</font></td>
               <td align=center><font size=-1>$row[7]</font></td>
               <td align=center><font size=-1><a href=mailto:$row[8]>$row[8]</font></a></td>
               <td align=center><font size=-1>$row[9]</font></td>
               <td align=center><font size=-1><a href=$admin_url?action=erase&num=$row[5]&start=$start>»èÁ¦</a></font></td></tr> ";
      }
            
      $n--;
    }
        
    echo "</table><br><br>";
         
    if($total>$scale)  
    {
      if($star+1>$scale*$page_scale)   
      {
        $pre_star=$star-$scale;
        echo"<a href='$PHP_SELF?star=$pre_star'> ÀÌÀü</a>";
      }
              
      for($vj=0; $vj < $page_scale ; $vj++) 
      {
        $ln=($page*$page_scale+$vj)*$scale;
                  
        $vk=$page*$page_scale+$vj+1;
                  
        if($ln < $total) 
        {
          if($ln!=$star)   
          {
            echo"<a href='$PHP_SELF?star=$ln'><font size=2>[$vk]</a></font>";
          }
          else    
          {
            echo"<font size-2><b>$vk</b></font>";
          }
        }
      }
              
      if($total>(($page+1)*$scale*$page_scale)) 
      {
        $n_star=($page+1)*$scale*$page_scale;
                  
        echo"<a href='$PHP_SELF?star=$n_star'>´ÙÀ½</a>";
      }
    }
                    
    ?>
    
            


6.15. Á¤±ÔÇ¥Çö½Ä

  1. Á¤±Ô½Ä Ç¥Çö

    a(b*) : a, ab, abb, a¿Í ÀÓÀÇÀÇ °¹¼öµé·Î µÈ ¹®ÀÚ¿­
    a(b+) : ab, abb, abbb, ab¿Í ÀÓÀÇÀÇ °¹¼öµé·Î µÈ ¹®ÀÚ¿­
    a(b?) : a or ab, a ´ÙÀ½¿¡ b°¡ À־ µÇ°í, ¾ø¾îµµ µÈ´Ù.
    a(b{3}) : abbb 
    a(b{2,}) : abb, abbb, abbbb, a ¿Í µÎ°³ ÀÌ»óÀÇ bµé·Î µÈ ¹®ÀÚ¿­
    a(b{2.4}) : abb, abbb, abbbb, a ¿Í µÎ°³ ÀÌ»ó, ³× °³ ÀÌÇÏÀÇ bµé·Î µÈ ¹®ÀÚ¿­
    
    [a-z] : a-z ±îÁö ¹®ÀÚ¿­
    [a-zA-Z0-9] : ÀÓÀÇ ¿µ¼ýÀÚ
            

  2. °ø¹é ¹®ÀÚ

    [^0-9] : ÀÓÀÇ ¼ýÀÚ°¡ ¾Æ´Ñ¹®ÀÚ
    [~a-zA-Z0-9]: ÀÓÀÌÀÇ ¿µ¼ýÀÚ°¡ ¾Æ´Ñ ¹®ÀÚ
            

  3. ÀÓÀÇÀÇ °ø¹é¹®ÀÚ°¡ ¾Æ´Ñ ¹®ÀÚ

    a.c : aac, abc, acc, a ¿Í c¿¡ ÀÓÀÇÀÇ ¹®ÀÚ Çϳª°¡ ³¢¾î ÀÖ´Â ¹®ÀÚ¿­
    ^a.* : a·Î ½ÃÀÛÇÏ´Â ÀÓÀÇÀÇ ¹®ÀÚ¿­
    [a-c]*x$ : x, ax, bx, abax, abcx, a¿¡¼­ c»çÀÌÀÇ ÀÓÀÇÀÇ ¹®ÀÚµé·ÎÀÌ·ç¾îÁö¸ç, ¸¶Áö¸· ¹®ÀÚ°¡ xÀÎ ¹®ÀÚ¿­
    b[ao]y : bay ¶Ç´Â boy¿¡ÀÎ ¹®ÀÚ¿­
    [^Zz]{5} : Z or z °¡ Æ÷ÇÔµÇÁö ¾ÊÀº ±æÀÌ°¡ 5ÀÎ ÀÓÀÇÀÇ ¹®ÀÚ¿­
    [[:digit:]] : ÀÓÀÇÀÇ ¼ýÀÚ , [0-9]
    [[:<:]a.* : a·Î ½ÃÀÛÇÏ´Â ÀÓÀÇÀÇ ¹®ÀÚ¿­
    
    ¿¹) ^([0-9]{2,4})(-[0-9]{3,4})(-[0-9]{3,4}) : ÀüÈ­¹øÈ£(xxxx-xxxx-xxxx)
            
    ÀÓÀÇÀÇ °ø¹é¹®ÀÚ°¡ ¾Æ´Ñ ¹®ÀÚ


6.16. ¿µ¾î ´Ü¾î °Ë»ö

  1. engdic ÇÁ·Î±×·¥ÀÌÀÖ³ª È®ÀÎÇÏ°í ¾øÀ¸¸é ¼³Ä¡ÇÑ´Ù.

    which engdic

  2. test.php, exec ¸¦ »ç¿ëÇؼ­ engdic ÇÁ·Î±×·¥À» ½ÇÇàÇÑ´Ù.

    <?
    
    // ¿µÇÑ/ »çÀü ÀÔ´Ï´Ù.
    function engdic($string) 
    {
      $cmd = "engdic $string";
      exec($cmd,$array,$rtn);
    
      for ($i=0; $i < count($array); $i++) 
      {
        $rstring .= "$array[$i]";
      }
      return $rstring;
    }
    
    print engdic("hello");
    
    ?>
            


6.17. IP ¼Ò¼Ó±â°ü,ȸ»ç ¾Ë¾Æº¸±â

  1. fwhois ÇÁ·Î±×·¥ÀÌÀÖ³ª È®ÀÎÇÏ°í ¾øÀ¸¸é ¼³Ä¡ÇÑ´Ù.

    which fwhois

  2. test.php, exec ¸¦ »ç¿ëÇؼ­ engdic ÇÁ·Î±×·¥À» ½ÇÇàÇÑ´Ù.

    <?
    
    //¾ÆÀÌÇÇ ¼Ò¼Ó ȸ»ç, ±â°ü ¾Ë¾Æ³»´Â ÇÔ¼ö
    function ip($string) 
    {
     $cmd = "fwhois $string"."@whois.nic.or.kr";
     exec($cmd,$array,$rtn);
    
     for ($i=0; $i < count($array); $i++) 
     {
       $rstring .= "$array[$i]";
      }
      return $rstring;
    }
    
    print ip("210.180.116.238");
    
    ?>
            


6.18. ÇöÀçÀÇ ³â/¿ù/ÀÏ ±¸Çϱâ

<?
function date_selector($name, $date) 
{
  $monthname = array(1=>"1¿ù", "2¿ù", "3¿ù", "4¿ù","5¿ù","6¿ù","7¿ù","8¿ù","9¿ù","10¿ù", "11¿ù","12¿ù");

  if($date == "") 
  {
    $date = time();
  }

  //³â
  print "<select name = ".$year." year > ";

  $start_year = date("Y", $date);

  for($current_year = $start_year - 5; $current_year <= $start_year + 5; $current_year++) 
  {
    print "<option value = $current_year";

    if(date("Y", $date) == $current_year) 
    {
      print " selected ";
    }

    print " > $current_year ";
  }
	
  print "</select>";
	
  //¿ù
  print "<select name = ".$month." month >";
  for($current_month = 1; $current_month <= 12; $current_month++) 
  {
    print "<option value = $current_month ";
		
    if(date("m", $date) == $current_month) 
    {
      print " selected ";
      print ">";
      print $monthname[$current_month];
			
    }
    else 
    {
      print ">";
      print $monthname[$current_month];
    }
		
    print " ";
  }

  print "</select>";

  //ÀÏ
  print "<select name = ".$day." day >";
	
  for($current_day = 1; $current_day <= 31; $current_day++) 
  {
    print "<option value = $current_day ";
    if(date("d", $date) == $current_day ) 
    {
      echo " selected ";
    }
    echo " > $current_day ÀÏ";
  }
	
  print "</select>";
}

echo "<html>
<head>
<title>¿¬½À</title>
<body>";

if(isset($month)) 
{
  //$use_date = mktime(0, 0, 0, $sample_month, $sample_day, $sample_year);
  $use_date = mktime(0, 0, 0, $month, $day, $year);
}
else 
{
	$use_date = time();
}

print "<form action = cal.php method = post>";
print date_selector("cal", $use_date);

echo "<input type = submit value = ÀÔ·Â>
</form>
</body>
</html>";

?>
    


7. ÀÚ¹Ù½ºÅ©¸³Æ®

7.1. idcheck¸¦ À§ÇÑ ¿¹Á¦

±âÁ¸¿¡ ¾ÆÀ̵𰡠ÀÖ³ª ¾ø³ª¸¦ üũ¸¦ Çϱâ À§Çؼ­.

idcheck.htm

<html>
<script language="JavaScript">

function id_chk(obj)
{
  var form = document.select1;
  var w_id_chk;
  if ( form.s_id.value == "" ) 
  {
    alert("¾ÆÀ̵𸦠ÀÔ·ÂÇÏÁö ¾Ê¾Ò½À´Ï´Ù.");
    form.s_id.focus();
    return;
  } else if ((form.s_id.value.toString().length < 4) || (form.s_id.value.toString().length > 10)) 
  {
    alert("¾ÆÀ̵ð´Â 4ÀÚÀÌ»ó 10ÀÚÀ̳»·Î ÀÔ·ÂÇÏ¿© Áֽʽÿä.");
    form.s_id.focus();
    return;
  }
  ck=1;
  var str = 'idcheck.php?s_id='+obj.s_id.value;
  window.open(str,'w_id_chk','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=150');
  return;
}

</script>

<body>
<form method=post name=select1 >
<table>
  <tr>
    <td width = 200 BGCOLOR="#F2F5F1" align = right><font size="2" color="red">*</font><font size="2">¼ö°­»ý ¾ÆÀ̵ð</font></td>
    <td width = 550><font size="2"><input type=text name=s_id size=8 maxlength=8> 
      <input TYPE='buton' NAME='chkbutton' VALUE='Áߺ¹¾ÆÀ̵ð È®ÀÎ' onClick="deny_javascript:id_chk(this.form);"></a>
        <br>4~8ÀÚ ¿µ¹®¼ýÀÚ Á¶ÇÕ, ù±ÛÀÚ´Â ¿µ¹®, ´ë¼Ò¹®ÀÚ ±¸º°¾ÈÇÔ</font></td>
    </tr>
</table>
</from>

</body>
</html>
    

idcheck.php

<html>
<body>
<?
include "db.ph";
db_connect();

$sth3 = mysql_query("select id from cls_member where id = '$s_id'");

$total = mysql_affected_rows(); //°Ô½Ã¹° ÃÑ ¼ö

if($total == "0") 
{
  print "<br><br><br><font size = 2>$s_id ´Â »ç¿ëÇÒ¼ö ÀÖ´Â ¾ÆÀ̵ð ÀÔ´Ï´Ù.</font>";
}
else 
{
  print "<br><br><br><font size = 2>$s_id ´Â ÀÌ¹Ì »ç¿ëÁßÀÎ ¾ÆÀ̵ð ÀÔ´Ï´Ù.</font>";
}

?>
</body>
</html>
    


7.2. ¸Þ´º ¸¸µé±â ¿¹Á¦

<html>
<script language="JavaScript">
<!--

// ¸¶¿ì½º¸¦ ÁÖ¸Þ´º À§¿¡ ¿Ã·Á ³õÀ¸¸é ºÎ¸Þ´º°¡ ³ª¿À°Ô ÇÏ´Â ½ºÅ©¸³Æ®
function MM_findObj(n, d) { //v3.0

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;

}


function MM_showHideLayers() { //v3.0

  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }

    obj.visibility=v; }

}


// ºÎ¸Þ´º ·Ñ¿À¹ö ±â´É
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-->


</script>

<body marginheight=0 marginwidth=0 topmargin=0 rightmargin=0 leftmargin="0" bgcolor="ffffff">
<table width="780" border="0" cellspacing="0" cellpadding="0" >

<tr><td height="67" ></td><td height="67" width="120"><img src="top_img/p0.gif"></td></tr>
<tr><td><a href="#" onMouseOver="MM_showHideLayers('about1','','show', 'glmoum','','hide')"><img name="about" border="0" src="menu_img/aboutus0.gif" width="85" height="33"></A><a href="#" onMouseOver="MM_showHideLayers('product1','','show', 'glmoum','','hide')"><img name="product" border="0" src="menu_img/product0.gif" width="73" height="33"></a><a href="#" onMouseOver="MM_showHideLayers('news1','','show', 'glmoum','','hide')"><img name="news" border="0" src="menu_img/news0.gif" width="54" height="33"></a><a href="#" onMouseOver="MM_showHideLayers('mdata','','show', 'glmoum','','hide')"><img name="data" border="0" src="menu_img/data0.gif" width="99" height="33"></a><a href="#" onMouseOver="MM_showHideLayers('mcollaborator','','show', 'glmoum','','hide')"><img name="coll" border="0" src="menu_img/collaborator0.gif" width="110" height="33"></a><a href="#" onMouseOver="MM_showHideLayers('mcontactus','','show', 'study','','hide')"><img name="contact" border="0" src="menu_img/contactus0.gif" width="99" height="33"></a><a href="#" onMouseOver="MM_showHideLayers('msitemap','','show', 'study','','hide')"><img name="map" border="0" src="menu_img/sitemap0.gif" width="74" height="33"></a><img name="map" border="0" src="top_img/blank.gif" width="66" height="33"></td><td height="33" width="120"><img src="top_img/p1.gif"></td></tr>


</table>


<!-- about us -->
<div id="about1" style="position:absolute; z-index:1; left: 0; top: 67 ;visibility: hidden"> 

<!-- ÁÖ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr>
   <td><img name="about" border="0" src="menu_img/aboutus1.gif" width="85" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('about1','','hide')"><img name="product" border="0" src="top_img/blank.gif" width="73" height="33"></a></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('about1','','hide')"><img name="product" border="0" src="menu_img/news0.gif" width="54" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('about1','','hide')"><img name="coll" border="0" src="menu_img/data0.gif" width="99" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('about1','','hide')"><img name="coll" border="0" src="menu_img/collaborator0.gif" width="110" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('about1','','hide')"><img name="contact" border="0" src="menu_img/contactus0.gif" width="99" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('about1','','hide')"><img name="contact" border="0" src="menu_img/sitemap0.gif" width="74" height="33"></td>
   </tr>
</table>

<table border="0" cellspacing="0" cellpadding="0" > <tr> 

<!--   ºÎ¸Þ´º -->
<td width=660 height="28" colspan="2" bgcolor="#0D3689"><a href="../about1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('about sub 1','','menu_img/about_11.gif',0)"><img name="about sub 1" border="0" src="menu_img/about_10.gif" width="154" height="28"></a><a href="../about2.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('about sub 2','','menu_img/about_21.gif',0)"><img name="about sub 2" border="0" src="menu_img/about_20.gif" width="85" height="28"></a><a href="../about3.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('about sub 3','','menu_img/about_31.gif',0)"><img name="about sub 3" border="0" src="menu_img/about_30.gif" width="102" height="28"></a><a href="../about4.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('about sub 4','','menu_img/about_41.gif',0)"><img name="about sub 4" border="0" src="menu_img/about_40.gif" width="86" height="28"></a><a href="about5.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('about sub 5','','menu_img/about_51.gif',0)"><img name="about sub 5" border="0" src="menu_img/about_50.gif" width="166" height="28"></a><a href="about6.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('about sub 6','','menu_img/about_61.gif',0)"><img name="about sub 6" border="0" src="menu_img/about_60.gif" width="67" height="28"></a></td><td height="28" width="120"><img src="top_img/blank.gif" WIDTH="100" HEIGHT="5"></td></tr>
</table>
</div>


<!-- product -->
<div id="product1" style="position:absolute; z-index:1; left: 0; top: 67 ;visibility: hidden"> 

<!--  ÁÖ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr> 
  <td><a href="#" onMouseOver="MM_showHideLayers('product1','','hide')"><img name="about" border="0" src="menu_img/aboutus0.gif" width="85" height="33"></a></td>
  <td><img name="product" border="0" src="menu_img/product1.gif" width="73" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('product1','','hide')"><img name="product" border="0" src="menu_img/news0.gif" width="54" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('product1','','hide')"><img name="coll" border="0" src="menu_img/data0.gif" width="99" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('product1','','hide')"><img name="coll" border="0" src="menu_img/collaborator0.gif" width="110" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('product1','','hide')"><img name="contact" border="0" src="menu_img/contactus0.gif" width="99" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('product1','','hide')"><img name="contact" border="0" src="menu_img/sitemap0.gif" width="74" height="33"></td>
  </tr> 
</table>

<!-- ºÎ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr> 
    <td width=660 height="28" colspan="2" bgcolor="#0D3689"><a href="product1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('product 1','','menu_img/product_11.gif',0)"><img name="product 1" border="0" src="menu_img/product_10.gif" width="80" height="28"></a><a href="product2.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('product 2','','menu_img/product_21.gif',0)"><img name="product 2" border="0" src="menu_img/product_20.gif" width="116" height="28"></a><a href="product3.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('product 3','','menu_img/product_31.gif',0)"><img name="product 3" border="0" src="menu_img/product_30.gif" width="148" height="28"></a><a href="product4.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('product 4','','menu_img/product_41.gif',0)"></td>
</tr> 
</table></div>

<!-- news -->
<div id="news1" style="position:absolute; z-index:1; left: 0; top: 67 ;visibility: hidden"> 

<!-- ÁÖ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr>
  <td><a href="#" onMouseOver="MM_showHideLayers('news1','','hide')"><img name="about" border="0" src="menu_img/aboutus0.gif" width="85" height="33"></a></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('news1','','hide')"><img name="product" border="0" src="menu_img/product0.gif" width="73" height="33"></a></td>
  <td><img name="product" border="0" src="menu_img/news1.gif" width="54" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('news1','','hide')"><img name="coll" border="0" src="menu_img/data0.gif" width="99" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('news1','','hide')"><img name="coll" border="0" src="menu_img/collaborator0.gif" width="110" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('news1','','hide')"><img name="contact" border="0" src="menu_img/contactus0.gif" width="99" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('news1','','hide')"><img name="contact" border="0" src="menu_img/sitemap0.gif" width="74" height="33"></td>
</table>

<!-- ºÎ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr>
    <td width=660 height="28" colspan="2" bgcolor="#0D3689"><a href="news1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('news 1','','menu_img/news_11.gif',0)"><img name="news 1" border="0" src="menu_img/news_10.gif" width="95" height="28"></a><a href="news2.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('news 2','','menu_img/news_21.gif',0)"><img name="news 2" border="0" src="menu_img/news_20.gif" width="179" height="28"></a><a href="news3.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('news 3','','menu_img/news_31.gif',0)"><img name="news 3" border="0" src="menu_img/news_30.gif" width="122" height="28"></a><a href="news4.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('news 4','','menu_img/news_41.gif',0)"></td>
</tr> 
</table></div>



<!-- data -->
<div id="mdata" style="position:absolute; height: 50; z-index:1; left: 0; top: 67; visibility: hidden"> 

<!-- ÁÖ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr> 
  <td><a href="#" onMouseOver="MM_showHideLayers('mdata','','hide')"><img name="about" border="0" src="menu_img/aboutus0.gif" width="85" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mdata','','hide')"><img name="product" border="0" src="menu_img/product0.gif" width="73" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mdata','','hide')"><img name="product" border="0" src="menu_img/news0.gif" width="54" height="33"></A></td>
  <td><img name="coll" border="0" src="menu_img/data1.gif" width="99" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mdata','','hide')"><img name="coll" border="0" src="menu_img/collaborator0.gif" width="110" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mdata','','hide')"><img name="contact" border="0" src="menu_img/contactus0.gif" width="99" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mdata','','hide')"><img name="contact" border="0" src="menu_img/sitemap0.gif" width="74" height="33"></td>
 </tr> 
</table>

<!-- ºÎ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr>
    <td width=660 height="28" colspan="2" bgcolor="#0D3689"><a href="data1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('data room 1','','menu_img/data_11.gif',0)"><img name="data room 1" border="0" src="menu_img/data_10.gif" width="85" height="28"></a><a href="data2.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('data room 2','','menu_img/data_21.gif',0)"><img name="data room 2" border="0" src="menu_img/data_20.gif" width="196" height="28"></a><a href="data3.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('data room 3','','menu_img/data_31.gif',0)"><img name="data room 3" border="0" src="menu_img/data_30.gif" width="111" height="28"></a><a href="data4.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image30','','menu_img/data_41.gif',0)"></td>
</tr> 
</table></div>


<! -- collaborator -->
<div id="mcollaborator" style="position:absolute; height: 50; z-index:1; left: 0; top: 67; visibility: hidden">

<!--  ÁÖ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr> 
  <td><a href="#" onMouseOver="MM_showHideLayers('mcollaborator','','hide')"><img name="about" border="0" src="menu_img/aboutus0.gif" width="85" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mcollaborator','','hide')"><img name="product" border="0" src="menu_img/product0.gif" width="73" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mcollaborator','','hide')"><img name="product" border="0" src="menu_img/news0.gif" width="54" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mcollaborator','','hide')"><img name="coll" border="0" src="menu_img/data0.gif" width="99" height="33"></A></td>
  <td><img name="coll" border="0" src="menu_img/collaborator1.gif" width="110" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mcollaborator','','hide')"><img name="contact" border="0" src="menu_img/contactus0.gif" width="99" height="33"></td>
  <td><a href="#" onMouseOver="MM_showHideLayers('mcollaborator','','hide')"><img name="contact" border="0" src="menu_img/sitemap0.gif" width="74" height="33"></td>
</table>

<!-- ºÎ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr>
    <td width=660 height="28" colspan="2" bgcolor="#0D3689"><a href="coll1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('collaborator 1','','menu_img/collaborator_11.gif',0)"><img name="collaborator 1" border="0" src="menu_img/collaborator_10.gif" width="129" height="28"></a><a href="coll2.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('collaborator 2','','menu_img/collaborator_21.gif',0)"><img name="collaborator 2" border="0" src="menu_img/collaborator_20.gif" width="158" height="28"></a></td>
</tr> 
</table></div>


<!-- contactus -->
<div id="mcontactus" style="position:absolute; height: 50; z-index:1; left: 0; top: 67; visibility: hidden"> 

<!-- ÁÖ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr> 
   <td><a href="#" onMouseOver="MM_showHideLayers('mcontactus','','hide')"><img name="about" border="0" src="menu_img/aboutus0.gif" width="85" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('mcontactus','','hide')"><img name="product" border="0" src="menu_img/product0.gif" width="73" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('mcontactus','','hide')"><img name="product" border="0" src="menu_img/news0.gif" width="54" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('mcontactus','','hide')"><img name="coll" border="0" src="menu_img/data0.gif" width="99" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('mcontactus','','hide')"><img name="coll" border="0" src="menu_img/collaborator0.gif" width="110" height="33"></A></td>
   <td><img name="contact" border="0" src="menu_img/contactus1.gif" width="99" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('mcontactus','','hide')"><img name="contact" border="0" src="menu_img/sitemap0.gif" width="74" height="33"></td>
</table>

<!-- ºÎ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr>

    <td width=660 height="28" colspan="2" bgcolor="#0D3689"><a href="contactus.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contactus 1','','menu_img/contactus_11.gif',0)"><img name="contactus 1" border="0" src="menu_img/contactus_10.gif" width="134" height="28"></a><a href="contactus2.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contactus 2','','menu_img/contactus_21.gif',0)"><img name="contactus 2" border="0" src="menu_img/contactus_20.gif" width="78" height="28"></a><a href="contactus3.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contactus 3','','menu_img/contactus_31.gif',0)"></td>

</tr> 
</table></div>

<! -- sitemap -->
<div id="msitemap" style="position:absolute; height: 50; z-index:1; left: 0; top: 67; visibility: hidden">

<!  -- ÁÖ¸Þ´º -->
<table border="0" cellspacing="0" cellpadding="0" > <tr>
   <td><a href="#" onMouseOver="MM_showHideLayers('msitemap','','hide')"><img name="about" border="0" src="menu_img/aboutus0.gif" width="85" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('msitemap','','hide')"><img name="product" border="0" src="menu_img/product0.gif" width="73" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('msitemap','','hide')"><img name="product" border="0" src="menu_img/news0.gif" width="54" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('msitemap','','hide')"><img name="coll" border="0" src="menu_img/data0.gif" width="99" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('msitemap','','hide')"><img name="coll" border="0" src="menu_img/collaborator0.gif" width="110" height="33"></td>
   <td><a href="#" onMouseOver="MM_showHideLayers('msitemap','','hide')"><img name="contact" border="0" src="menu_img/contactus0.gif" width="99" height="33"></td>
   <td><img name="map" border="0" src="menu_img/sitemap1.gif" width="74" height="33"></td>
   </tr>
</table>
<!-- ºÎ¸Þ´º -->
</table><table border="0" cellspacing="0" cellpadding="0" > <tr><td></td></tr> 
</table>
</div>

</table>
</body>
</html>
    


8. Oracle

  1. Å×ÀÌºí ±¸Á¶

    id int, name char(20), age int, addr(20)

  2. test.php

     
    <?php 
    $conn = OCILogon("scott","tiger"); //·Î±×ÀÎÀ» ÇÑ´Ù. 
    
    $stmt = OCIParse($conn,"select * from test"); //testÅ×À̺íÀÇ ³»¿ëÀ» º¯¼ö¿¡ ÀúÀåÇÑ´Ù. 
    
    OCIExecute($stmt); //ÀúÀåÇÑ º¯¼ö¸¦ È°¼ºÈ­ ÇÑ´Ù. 
    
    while (OCIFetchInto($stmt, $col, OCI_NUM)) 
    { //º¯¼öÀÇ ³»¿ëÀ» °¡Á®¿Â´Ù. 
    
      echo "". $col[0]."....". $col[1]."....". $col[2]."....". $col[3]." "; 
      //Å×À̺íÀÇ ³»¿ëÀ» Ãâ·Â ½ÃŲ´Ù. 
    } 
    
    OCIFreeStatement($stmt); // º¯¼öÀÇ ³»¿ëÀ» Áö¿î´Ù. 
    
    OCILogoff($conn);// ·Î±× ¿ÀÇÁ¸¦ ÇÑ´Ù. 
    ?>
          


9. Mysql

9.1. mysql ÁÖ±âÀûÀ¸·Î ¹é¾÷Çϱâ

  1. myhome_bakcup ¼¿½ºÅ©¸³Æ®

    #!/bin/bash
    
    T=$(echo `date +%Y%m%d%H%M`)
    MY=$(echo /home/nalabi/backup)
    
    echo "nalabi ÀÇ µ¥ÀÌŸ°¡ ¹é¾÷ µÇ¾ú½À´Ï´Ù. $T"
    
    mysqldump myhome > $MY/myhome$T.sql
    gzip $MY/myhome$T.sql
            

  2. /etc/crontab »ç¿ëÇϱâ

    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=root
    HOME=/
    
    # run-parts
    01 * * * * root run-parts /etc/cron.hourly
    02 4 * * * root run-parts /etc/cron.daily
    22 4 * * 0 root run-parts /etc/cron.weekly
    42 4 1 * * root run-parts /etc/cron.monthly
            

    Çü½Ä :

    a b c d e id runparts directory

    ºÐ(0~59) ½Ã(0~24) ³¯Â¥(0~31) ´Þ(0~12) ¿äÀÏ(0~7) id(Å©·ÐÀÌ »ç¿ëÇÒ °èÁ¤) directory(½ÇÇàÇÏ°ÔµÉ ÆÄÀÏ ³õÀÌ°Ô µÉ °æ·Î)

    ¿¹Á¦ :

    15 14 1 * * root /home/nalabi/backup/myhome_backup

    ¸Å´Þ 1ÀÏ ¿ÀÈÄ 2½Ã 15¿¡ myhome_backupÀ» ½ÇÇàÇÑ´Ù.

    0 22 * * 1-5 root /home/nalabi/backup/myhome_backup

    ¿ù¿äÀÏ ºÎÅÍ ±Ý¿äÀϱîÁö ¸ÅÀÏ ¿ÀÈÄ 8½Ã¿¡ myhome_backupÀ» ½ÇÇàÇÑ´Ù.

    23 0-23/2 * * * root /home/nalabi/backup/myhome_backup

    ¸ÅÀÏ 0, 2, 4, ....½Ã 23ºÐ¿¡ ½ÇÇàÇÑ´Ù.


9.2. mysql ·çÆ® Æнº¿öµå¸¦ ÀÒ¾î ¹ö·ÈÀ» ¶§

mysql ÁßÁöÇÑ´Ù.

/etc/init.d/mysql stop

µ¥¸óÀ» ¾Æ¹«³ª µé¾î°¥¼ö ÀÖ°Ô ´Ù½Ã ½ÇÇàÇÑ´Ù.

      safe_mysqld --skip-grant &
    

·çÆ® Æнº¿öµå¸¦ º¯°æÇÑ´Ù.

      mysql> update user set password='' where user='root';
    

mysql À» Àç½Ãµ¿ ÇÕ´Ï´Ù.

      /etc/init.d/mysql stop
      /etc/init.d/mysql start
    


9.3. µ¥ÀÌŸ ŸÀÔ (Å×ÀÌºí »ý¼º½Ã Ä÷³ÀÇ µ¥ÀÌŸ ŸÀÔÀÔ´Ï´Ù.)

  1. ¼öÄ¡ µ¥ÀÌÅÍ Å¸ÀÔ

              * INTEGER (INT) 
              * SMALLINT 
              * NUMBER 
              * DECIMAL(DEC) (x,y) : x´Â ½Ç¼öÀÚ¸®, y´Â ¼Ò¼öÁ¡ ÀÌÇÏÀÚ¸® 
              * FLOAT 
            

  2. ¹®ÀÚ µ¥ÀÌÅÍ Å¸ÀÔ

     
              * VARCHAR (n) : 8ºñÆ® ¹®ÀÚ ±æÀÌ°¡ ÃÖ´ë n°³ÀÎ ¹®ÀÚ¿­ 
              *CHARACTER(CHAR) (n) : n°³ÀÇ 8ºñÆ® ¹®ÀÚ¿­ 
              * LONG 
            

  3. ±×¿ÜÀǵ¥ÀÌÅÍ Å¸ÀÔ

              * DATE/TIME : ³¯Â¥/½Ã°£ 
              * LONG RAW 
            


9.4. ½©¿¡¼­ DB ³»¿ë º¸±â

mysqlshow

+-----------+ 
|Databases | 
+-----------+ 
| board | 
| kedu | 
| mysql | 
| test | 
+-----------+ 
    


9.5. Mysql¿¡ µé¾î°¡±â

mysql test

Reading table information for completion of table and column names 
You can turn off this feature to get a quicker startup with-A 

Welcome to the MySQL monitor. Commands end with ; or g. 
Your MySQL connection id is 7 to server version: 3.22.23b 

Type 'help' for help. 

mysql> 
    


9.1. µ¥ÀÌŸ ¹é¾÷ ¹Þ±â (È­ÀÏ·Î ¹ÞÀ½)

mysqldump ¸¦ ÀÌ¿ëÇؼ­ sql µ¥ÀÌŸ¸¦ ¹é¾÷ ¹ÞÀ»¼ö ÀÖÀ¸¸ç DBÀ̸§¸¸ ÁöÁ¤Çϸé Àüü Å×À̺íÀÌ, Å×À̺í À̸§ ±îÁö ÁöÁ¤Çϸé ÇØ´ç Å×ÀÌºí¸¸ ¹é¾÷À» ÇÒ¼ö ÀÖ´Ù.

mysqldump DBÀ̸§ (tableÀ̸§) > È­ÀÏÀ̸§

mysqldump test test > test.sql

# MySQL dump 6.0 
# 
# Host: localhost Database: test 
#-------------------------------------------------------- 
# Server version 3.22.23b 

# 
# Table structure for table 'test' 
# 
CREATE TABLE test ( 
no int(11), 
name char(10), 
tel char(15), 
addr char(20), 
sex char(1), 
birth date 
); 

# 
# Dumping data for table 'test' 
# 

INSERT INTO test VALUES (2,'ÀÌÁÖ»ó','02-504-xxxx','°úõ½Ã','m','1971-02-02'); 
INSERT INTO test VALUES (3,'ÀÓÁ¤³²','02-420-xxxx','¼ÛÆı¸','f','1971-03-03'); 
INSERT INTO test VALUES (4,'°­Çà¸ð','02-856-xxxx','°ü¾Ç±¸','f','1971-04-04'); 
INSERT INTO test VALUES (5,'ÀÌÇö¿µ','0342-718-xxxx','ºÐ´ç±¸','m','1971-05-05'); 
INSERT INTO test VALUES (6,'À̺´È¯','02-891-xxxx','ÇϾȵ¿','m','1980-06-06'); 
INSERT INTO test VALUES (1,'³²»ó¿í','333-4444','µ¿ÀÛ±¸','m','1971-01-01'); 
    


9.2. µ¥ÀÌŸ ÀÔ·ÂÇϱâ (È­ÀÏ--> Mysql)

mysql test < test.sql

Âü°í·Î µ¥ÀÌŸ È®ÀÎÀº mysql -e "select * from test" test

 
+------+--------+---------------+--------+------+------------+ 
| no | name | tel | addr | sex | birth | 
+------+--------+---------------+--------+------+------------+ 
| 2 |ÀÌÁÖ»ó | 02-504-xxxx | °úõ½Ã | m | 1971-02-02 | 
| 3 | ÀÓÁ¤³² | 02-420-xxxx | ¼ÛÆı¸ | f | 1971-03-03 | 
| 4 | °­Çà¸ð | 02-856-xxxx | °ü¾Ç±¸ | f | 1971-04-04 | 
| 5 | ÀÌÇö¿µ | 0342-718-xxxx | ºÐ´ç±¸ | m | 1971-05-05 | 
| 6 | À̺´È¯ | 02-891-xxxx | ÇϾȵ¿ | m | 1980-06-06 | 
| 1 | ³²»ó¿í | 333-4444 | µ¿ÀÛ±¸ | m | 1971-01-01 | 
+------+--------+---------------+--------+------+------------+ 
    


9.3. »ç¿ëÀÚ ¸¸µé±â

  1. aaaa¶ó´Â »ç¿ëÀÚ(user)¸¦ ¸¸µì´Ï´Ù.

    mysql mysql(mysql db·Î µé¾î°©´Ï´Ù.)

     
    mysql>insert into user values ('localhost','aaaa','','y','y','y','y','y','y','y','y','y','y','y','y','y','y'); 
    Query OK, 1 row affected (0.04 sec) 
            

    reload ¸¦ ²À ½ÇÇà½Ãŵ´Ï´Ù.(½©¿¡¼­)

    mysqladmin reload

  2. aaaa¶ó´Â »ç¿ëÀÚ¿¡°Ô aaaa¶ó´Â ºñ¹Ð¹øÈ£¸¦ ºÎ¿©ÇÕ´Ï´Ù.

    mysqladmin -u aaaa password aaaa

    mysqladmin reload

  3. µ¥ÀÌŸ º£À̽º ¸¸µé±â

    »ç¿ëÀÚ°¡ ¾øÀ» °æ¿ì : mysqladmin create aaaa

    »ç¿ëÀÚ¿Í ºñ¹Ð¹øÈ£°¡ ÀÖ´Â °æ¿ì : mysqladmin -u aaaa -p create aaaa (or) mysqladmin -u aaaa -paaaa create aaaa

  4. ¼­¹öÀÇ µ¥ÀÌŸ º£À̽º ²ø¾î¿À±â

    ¼­¹ö »óÀÇ µ¥ÀÌŸ º£À̽º¸¦ ³ªÀÇ ÄÄÀÇ ÇÁ·Î±×·¥À¸·Î °¡Á® ¿Ã¶§ »ç¿ëÇÕ´Ï´Ù.

    ¼­¹öÀÇ mysql mysql À» ½ÇÇà ÇÕ´Ï´Ù.

    INSERT INTO db VALUES ('³ªÀÇ ÄÄ ¾ÆÀÌÇÇ','DBÀ̸§','»ç¿ëÀÚ','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

    INSERT INTO user VALUES ('³ªÀÇ ÄÄ ¾ÆÀÌÇÇ '»ç¿ëÀÚ ','ºñ¹Ð¹øÈ£ ','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

    ±×¸®°í, À§ÀÇ Äù¸®¹®À» ÆíÁýÇؼ­ ½ÇÇà ÇÕ´Ï´Ù.

    ±×·Á¸é ³ªÀÇ ÄÄ¿¡ DB°¡ ¾ø¾îµµ ¼­¹öÀÇ DB¸¦ °¡Á®¿Í¼­ »ç¿ëÀ» ÇÒ¼ö°¡ ÀÖ½À´Ï´Ù.


9.4. Å×ÀÌºí ¸¸µé±â

»ç¿ë¹ý : create table Å×À̺íÀ̸§(º¯¼ö¸í º¯¼ö°ª, ......);

mysql> create table test (no int, name char(10), age int, tel char(15)); 
Query OK, 0 rows affected (0.00 sec) 
    


9.5. Å×ÀÌºí º¸±â

»ç¿ë¹ý : show tables;

mysql> show tables; 
   +-----------------+ 
   | Tables in test | 
   +-----------------+ 
   | test | 
   +-----------------+ 
   2 rows in set (0.00 sec) 

mysql> show tables like 'ad_%';
   +-------------------------+
   | Tables_in_dbkedu (ad_%) |
   +-------------------------+
   | ad_expose               |
   | ad_img                  |
   | ad_redirect             |
   | address                 |
   +-------------------------+
   4 rows in set (0.00 sec)
    


9.6. Å×ÀÌºí µ¥ÀÌŸ ÀÔ·ÂÇϱâ

mysql > insert into test values(1,'±è¿ëÀÏ','29','02-825-xxxx'); 
Query OK, 1 row affected (0.00 sec) 
    


9.7. ƯÁ¤ Çʵ常 ÀÔ·Â

mysql> insert into test (no,name) values ('7','³²»ó¿í'); 
Query OK,1 row affected (0.00 sec) 
    


9.8. Å×ÀÌºí³»¿ë º¸±â

select ¹®À» ÀÌ¿ëÇÑ´Ù.

mysql> select * from test; 
+------+--------+------+---------------+ 
| no | name | age | tel | 
+------+--------+------+---------------+ 
| 1 | ±è¿ëÀÏ | 29 | 02-825-xxxx | 
| 2 | ÀÌÁÖ»ó | 29 | 02-504-xxxx | 
| 3 | ÀÓÁ¤³² | 29 | 02-420-xxxx | 
| 4 | °­Çà¸ð| 29 | 02-856-xxxx | 
| 5 | ÀÌÇö¿µ | 29 | 0342-718-xxxx | 
| 6 |À̺´È¯ | 12 |02-891-xxxx | 
| 7 | ³²»ó¿í | NULL | NULL | 
+------+--------+------+---------------+ 
7 rows in set (0.00 sec) 
    


9.9. Çʵå Ãß°¡

alter ¹®À» ÀÌ¿ëÇÑ´Ù.

mysql> alter table test add addr char(20); 
Query OK, 1 row affected (0.00 sec) 
Records: 1 Duplicates: 0 Warnings: 0 

mysql> desc test; 
+-------+----------+------+-----+---------+-------+ 
| Field | Type | Null | Key | Default | Extra | 
+-------+----------+------+-----+---------+-------+ 
| no |int(11) | YES | | NULL | | 
| name | char(10) | YES | | NULL | | 
| age | int(11) | YES | | NULL | | 
| tel | char(15) | YES | | NULL | | 
| addr | char(20) | YES | | NULL | | 
+-------+----------+------+-----+---------+-------+ 
5 rows in set (0.00 sec) 
    


9.10. ÇÊµå »èÁ¦

alter ¹®À» ÀÌ¿ëÇÑ´Ù.

mysql> alter table test drop age; 
Query OK, 6 rows affected (0.01 sec) 
Records: 6 Duplicates: 0 Warnings: 0 
    


9.11. ±âŸ alter ¿ë¹ý

alter ¹®À» ÀÌ¿ëÇÑ´Ù.

ALTER TABLE¿¡´Â ´ÙÀ½ ¼¼°¡Áö Çü½ÄÀÌ ÀÖ½À´Ï´Ù.

ALTER TABLE table_name ADD ( ... ) ;

ALTER TABLE table_name MODIFY( ... ) ;

ALTER TABLE table_name DROP PRIMARYKEY ;

  1. ALTER TABLE t1 RENAME t2;

    Å×À̺í À̸§À» t1¿¡¼­ t2·Î ¹Ù²Þ

  2. ALTER TABLE t2 CHANGE a a TINYINT NOT NULL, CHANGE b c CHAR(20);

    Å×ÀÌºí ³»ÀÇ Ä÷³ ¼Ó¼ºÀ» ¹Ù²Þ

    ¿ø·¡ Ä÷³ a´Â INTEGER¿´´Âµ¥ TINYINT·Î,

    Ä÷³b´Â CHAR(10)À̾ú´Âµ¥ Ä÷³À̸§Àº c·Î ÀÌŸ ŸÀÔÀº CHAR(20)À¸·Î ¼öÁ¤

  3. ALTER TABLE t2 ADD d TIMESTAMP;

    Å×À̺í t2¿¡ d¶ó´ÂÀ̸§À¸·Î TIMESTAMP ÇüÀ¸·Î Ãß°¡

  4. ALTER TABLE t2 ADD INDEX (d), ADD PRIMARY KEY (a);

    »õ·Î¿î ÀÎÅؽº¸¦ »ý¼º Ä÷³ a¿¡ primary key »ý¼º.

  5. ALTER TABLE test MODIFY (age NUMBER NULL );

    NOT NULLÀ» NULL·Î ¹Ù²Ù±â

  6. ALTER TABLE test MODIFY (age NUMBER NOT NULL );

    NULLÀ» NOT NULL·Î ¹Ù²Ù±â

  7. ALTER TABLEtest MODIFY (name VARCHAR2( 20 ) );

    ¿­ÀÇ Æø ´ÃÀ̱â

  8. ALTER TABLE test MODIFY (name VARCHAR2( 15 ) );

    ¿­ÀÇ Æø ÁÙÀ̱â

  9. ALTER TABLE t2 DROP COLUMN c;

    Ä÷³ c¸¦ ¾ø¾Ö¹ö¸®°í

  10. ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD INDEX (c);

    t2 Å×ÀÌºí¿¡ c¶ó´Â Ä÷³À» »õ·Î »ý¼º½ÃÅ°´Âµ¥

    INT (INTEGER) : Á¤¼ö

    UNSIGNED : ¾ç¼ö

    NOT NULL : ¾Æ¹«µ¥ÀÌŸ°¡ ¾øÀ¸¸é '0'

    AUTO_INCREMENT : µ¥ÀÌŸ°¡ ÀÚµ¿ÀûÀ¸·Î ÀԷµÊ...

    ADD INDEX (c) : Ä÷³ c¿¡ ´ëÇؼ­ ÀÎÅؽº »ý¼º


9.12. µ¥ÀÌŸ »èÁ¦

delete ¸¦ ÀÌ¿ëÇÑ´Ù.

mysql>delete from test where name='±è¿ëÀÏ'; 
Query OK, 1 row affected(0.00 sec) 
    


9.13. µ¥ÀÌŸ ¼öÁ¤

update¸¦ ÀÌ¿ëÇÑ´Ù.

 
mysql> update test set no=1,tel='333-4444' where name='³²»ó¿í'; 
Query OK, 1 row affected (0.01 sec) 
Rows matched: 1 Changed: 1 Warnings: 0 
    

mysql> update test set addr='µ¿ÀÛ±¸' where no='1'; 
    


9.14. ³»¸² Â÷¼øÀ¸·Î Á¤·Ä

order¹®À» ÀÌ¿ë

mysql> select * from test order by no desc; 
+------+--------+------+---------------+--------+ 
| no | name | age | tel | addr | 
+------+--------+------+---------------+--------+ 
| 6 | À̺´È¯ |12 | 02-891-xxxx | NULL | 
| 5 | ÀÌÇö¿µ | 29 | 0342-718-xxxx | NULL | 
| 4 | °­Çà¸ð | 29 | 02-856-xxxx | NULL | 
| 3 | ÀÓÁ¤³² | 29 | 02-420-xxxx | NULL | 
| 2| ÀÌÁÖ»ó | 29 | 02-504-xxxx | NULL | 
| 1 | ³²»ó¿í | NULL | 333-4444 | µ¿ÀÛ±¸ | 
+------+--------+------+---------------+--------+ 
6 rows in set (0.01 sec) 
    


9.15. ¹«ÀÛÀ§ Á¤·Ä

rand¹®À» ÀÌ¿ë

mysql> select * from test order by rand(); 
+------+--------+---------------+--------+------+------------+ 
| no | name | tel | addr | sex | birth | 
+------+--------+---------------+--------+------+------------+ 
| 5 | ÀÌÇö¿µ | 0342-718-xxxx | ºÐ´ç±¸ | m | 1971-05-05 | 
| 4 | °­Çà¸ð | 02-856-xxxx | °ü¾Ç±¸ | f | 1971-04-04 | 
| 2 | ÀÌÁÖ»ó | 02-504-xxxx | °úõ½Ã | m | 1971-02-02 | 
| 1 | ³²»ó¿í | 333-4444 | µ¿ÀÛ±¸ | m | 1971-01-01 | 
| 6 | À̺´È¯ | 02-891-xxxx | ÇϾȵ¿ | m | 1980-06-06 | 
| 3 | ÀÓÁ¤³² | 02-420-xxxx | ¼ÛÆı¸ | f | 1971-03-03 | 
+------+--------+---------------+--------+------+------------+ 
6 rows in set (0.01 sec) 
    


9.16. ³âµµ¼øÀ¸·Î Á¤·Ä

year¹® ÀÌ¿ë

mysql> select * from test order by year(birth) desc; 
+------+--------+---------------+--------+------+------------+ 
| no | name | tel | addr | sex | birth | 
+------+--------+---------------+--------+------+------------+ 
| 6 | À̺´È¯ | 02-891-xxxx | ÇϾȵ¿ | m | 1980-06-06 | 
| 2 | ÀÌÁÖ»ó | 02-504-xxxx | °úõ½Ã | m | 1971-02-02 | 
| 3 | ÀÓÁ¤³² | 02-420-xxxx | ¼ÛÆı¸ | f | 1971-03-03 | 
| 4 | °­Çà¸ð | 02-856-xxxx | °ü¾Ç±¸ | f | 1971-04-04 | 
| 5 | ÀÌÇö¿µ | 0342-718-xxxx | ºÐ´ç±¸ | m | 1971-05-05 | 
| 1 | ³²»ó¿í | 333-4444 | µ¿ÀÛ±¸ | m | 1971-01-01 | 
+------+--------+---------------+--------+------+------------+ 
6 rows in set (0.00 sec) 
    


9.17. ³âµµ, ¹øÈ£¼øÀ¸·Î Á¤·Ä

year ¹® ÀÌ¿ë

mysql> select * from test order by year(birth) desc, no desc; 
+------+--------+---------------+--------+------+------------+ 
| no | name | tel | addr | sex | birth | 
+------+--------+---------------+--------+------+------------+ 
| 6 | À̺´È¯ | 02-891-xxxx | ÇϾȵ¿ | m | 1980-06-06 | 
| 5 | ÀÌÇö¿µ | 0342-718-xxxx | ºÐ´ç±¸ | m | 1971-05-05 | 
| 4 | °­Çà¸ð | 02-856-xxxx | °ü¾Ç±¸ | f | 1971-04-04| 
| 3 | ÀÓÁ¤³² | 02-420-xxxx | ¼ÛÆı¸ | f | 1971-03-03 | 
| 2 | ÀÌÁÖ»ó | 02-504-xxxx | °úõ½Ã | m | 1971-02-02 | 
| 1 | ³²»ó¿í | 333-4444 | µ¿ÀÛ±¸ | m | 1971-01-01 | 
+------+--------+---------------+--------+------+------------+ 
    


9.18. 20»ì ÀÌ»óÀÌ ¸î¸íÀΰ¡¸¦ ã´Â´Ù.

where Àý ÀÌ¿ë

mysql> select count(*) from test where age >=20; 
+----------+ 
| count(*) | 
+----------+ 
| 4 | 
+----------+ 
1 row in set (0.00 sec) 
    


9.19. null °ª °Ë»öÇϱâ

null ¹® ÀÌ¿ë

mysql> select * from test where addr is not null; 
+------+--------+------+----------+--------+ 
| no | name | age | tel | addr | 
+------+--------+------+----------+--------+ 
| 1 | ³²»ó¿í | NULL | 333-4444 | µ¿ÀÛ±¸ | 
+------+--------+------+----------+--------+ 
1 row in set (0.00 sec) 
    


9.1. null °ª °Ë»öÇϱâ

null ¹® ÀÌ¿ë

mysql> select * from test whereaddr is null; 
+------+--------+------+---------------+------+ 
| no | name | age | tel | addr | 
+------+--------+------+---------------+------+ 
| 2 | ÀÌÁÖ»ó | 29 | 02-504-xxxx | NULL | 
| 3 | ÀÓÁ¤³² | 29| 02-420-xxxx | NULL | 
| 4 | °­Çà¸ð | 29 | 02-856-xxxx | NULL | 
| 5 | ÀÌÇö¿µ | 29 | 0342-718-xxxx | NULL | 
| 6 | À̺´È¯ | 12| 02-891-xxxx | NULL | 
+------+--------+------+---------------+------+ 
5 rows in set (0.01 sec) 
    


9.2. °Ë»ö Çϱâ

like ÀÌ¿ë

  
mysql> select * from test where name like '%ÀÌ%'; 
+------+--------+------+---------------+------+ 
| no | name | age | tel | addr | 
+------+--------+------+---------------+------+ 
| 2 | ÀÌÁÖ»ó | 29 | 02-504-xxxx | NULL | 
| 5 | ÀÌÇö¿µ | 29 | 0342-718-xxxx | NULL | 
| 6 | À̺´È¯ | 12 | 02-891-xxxx | NULL | 
+------+--------+------+---------------+------+ 
3 rows in set (0.00 sec) 
    


9.3. ¹üÀ§ °Ë»ö

µîÈ£, ºÎµîÈ£ ¸¦ ÀÌ¿ëÇؼ­ °Ë»ö

mysql> select * from test where age>=10 and age <=20; 
+------+--------+------+-------------+------+ 
| no | name | age | tel | addr | 
+------+--------+------+-------------+------+ 
| 6 | À̺´È¯ | 12 | 02-891-xxxx | NULL | 
+------+--------+------+-------------+------+ 
1 row in set (0.00 sec) 
    


9.4. in °Ë»ö

in ¹®À» ÀÌ¿ëÇؼ­ °Ë»ö

mysql> select * from test where addr in('µ¿ÀÛ±¸','°ü¾Ç±¸'); 
+------+--------+------+-------------+--------+ 
| no | name | age | tel | addr | 
+------+--------+------+-------------+--------+ 
| 4 | °­Çà¸ð | 29 | 02-856-xxxx | °ü¾Ç±¸ | 
| 1 | ³²»ó¿í | NULL | 333-4444 | µ¿ÀÛ±¸ | 
+------+--------+------+-------------+--------+ 
2 rows in set (0.00 sec) 
    


9.5. not in °Ë»ö

not in¹®À» ÀÌ¿ëÇؼ­ °Ë»ö

mysql> select * from test where addr not in('µ¿ÀÛ±¸','°ü¾Ç±¸'); 
+------+--------+------+---------------+--------+ 
| no | name | age | tel | addr | 
+------+--------+------+---------------+--------+ 
| 2 | ÀÌÁÖ»ó | 29 |02-504-xxxx | °úõ½Ã | 
| 3 | ÀÓÁ¤³² | 29 | 02-420-xxxx | ¼ÛÆı¸ | 
| 5 | ÀÌÇö¿µ | 29 | 0342-718-xxxx | ºÐ´ç±¸ | 
| 6 | À̺´È¯ | 12 | 02-891-xxxx | ÇϾȵ¿ | 
+------+--------+------+---------------+--------+ 
4 rows in set (0.00 sec) 
   

ġȯ °Ë»ö

mysql> select * from cls_class as a, cls_member as b where b.g_code = 'h0001_3_2' and b.g_code=a.g_code;
   


9.6. ³¯Â¥ °Ë»öÇϱâ

where Àý ÀÌ¿ë

mysql> SELECT COUNT(no) FROM brd_free WHERE date = '2000-02-17';
+-----------+
| COUNT(no) |
+-----------+
|         1 |
+-----------+
1 row in set (0.03 sec)
    


9.7. Å×ÀÌºí ³»¿ëÀ» È­ÀÏ·Î ¸¸µé±â

²À °æ·Î¸¦ ÁöÁ¤ÇؾßÇÔ

 
mysql> select * from test into outfile '/root/test.txt'; 
    

°á°ú

2 ÀÌÁÖ»ó 02-504-xxxx °úõ½Ã m 1971-02-02 
3 ÀÓÁ¤³² 02-420-xxxx ¼ÛÆı¸ f 1971-03-03 
4 °­Çà¸ð 02-856-xxxx °ü¾Ç±¸ f 1971-04-04 
5 ÀÌÇö¿µ 0342-718-xxxx ºÐ´ç±¸ m 1971-05-05 
6 À̺´È¯ 02-891-xxxx ÇϾȵ¿ m 1980-06-06 
1 ³²»ó¿í 333-4444 µ¿ÀÛ±¸ m 1971-01-01 
    


9.8. Å×ÀÌºí ³»¿ëÀ» È­ÀÏ·Î ¸¸µé¶§ |·Î ±¸ºÐÇϱâ

terminated ¹®À» ¾´´Ù.

mysql> select * from test into outfile '/root/test.txt' fields terminated by '|'; 
    

°á°ú

2|ÀÌÁÖ»ó|02-504-xxxx|°úõ½Ã|m|1971-02-02 
3|ÀÓÁ¤³²|02-420-xxxx|¼ÛÆı¸|f|1971-03-03 
4|°­Çà¸ð|02-856-xxxx|°ü¾Ç±¸|f|1971-04-04 
5|ÀÌÇö¿µ|0342-718-xxxx|ºÐ´ç±¸|m|1971-05-05 
6|À̺´È¯|02-891-xxxx|ÇϾȵ¿|m|1980-06-06 
1|³²»ó¿í|333-4444|µ¿ÀÛ±¸|m|1971-01-01 
    


9.9. È­ÀÏÀ» ºÒ·¯¿À±â

load ¸í·É¾î¸¦ ¾´´Ù.

mysql> load data infile '/root/test.txt' replace into table test fields terminated by '|'; 
Query OK, 6 rows affected (0.02 sec) 
Records: 6 Deleted: 0 Skipped: 0 Warnings: 0 
    

°á°ú

mysql> select * from test; 
+------+--------+---------------+--------+------+------------+ 
| no | name | tel | addr | sex | birth | 
+------+--------+---------------+--------+------+------------+ 
| 2 |ÀÌÁÖ»ó | 02-504-xxxx | °úõ½Ã | m | 1971-02-02 | 
| 3 | ÀÓÁ¤³² | 02-420-xxxx | ¼ÛÆı¸ | f | 1971-03-03 | 
| 4 | °­Çà¸ð | 02-856-xxxx | °ü¾Ç±¸| f | 1971-04-04 | 
| 5 | ÀÌÇö¿µ | 0342-718-xxxx | ºÐ´ç±¸ | m | 1971-05-05 | 
| 6 | À̺´È¯ | 02-891-xxxx | ÇϾȵ¿ | m | 1980-06-06 | 
| 1 |³²»ó¿í | 333-4444 | µ¿ÀÛ±¸ | m | 1971-01-01 | 
+------+--------+---------------+--------+------+------------+ 
    


9.1. »çÄ¢¿¬»ê

* SUM (Column_name) : ƯÁ¤ Ä÷³¿¡¼­ Á¶°Ç¿¡ ¸¸Á·ÇÏ´Â ¸ðµç¿­ÀÇ °ªÀ» ´Ù´õÇÔ

* AVG (Column_name) : Æò±Õ°ª ÃßÃâ

* MAX (Column_name) : ÃÖ´ë°ªÃßÃâ

* MIN (Column_name) : ÃÖ¼Ò°ª ÃßÃâ

* COUNT (Column_name): ¿­ÀǼö¸¦ ÃßÃâ

sum ¹® »ç¿ëÇϱâ

mysql> select sum(age) from test; 
+----------+ 
| sum(age) | 
+----------+ 
| 128 | 
+----------+ 
1 row in set (0.00 sec) 
    

/±â »ç¿ëÇϱâ

mysql> select no, age, (no+age), (no+age)/2 from test; 
+------+------+----------+------------+ 
| no | age | (no+age) | (no+age)/2 | 
+------+------+----------+------------+ 
| 2 | 29 | 31 | 15.50 | 
| 3 | 29 | 32 | 16.00| 
| 4 | 29 | 33 | 16.50 | 
|5 | 29 | 34 | 17.00 | 
| 6 | 12 | 18 | 9.00 | 
| 1 | NULL | NULL | NULL | 
+------+------+----------+------------+ 
6 rows in set (0.00 sec) 
    


9.2. ³ªÀÌ °è»êÇϱâ

yser ¹® »ç¿ëÇϱâ

mysql> select *, year(curdate())-year(birth)+1 as age from test; 
+------+--------+---------------+--------+------+------------+------+ 
| no | name | tel | addr | sex | birth | age | 
+------+--------+---------------+--------+------+------------+------+ 
| 2 | ÀÌÁÖ»ó | 02-504-xxxx | °úõ½Ã | m | 1971-02-02 |29 | 
| 3 | ÀÓÁ¤³² | 02-420-xxxx | ¼ÛÆı¸ |f | 1971-03-03 | 29 | 
| 4 | °­Çà¸ð | 02-856-xxxx | °ü¾Ç±¸ | f | 1971-04-04 | 29 | 
| 5 |ÀÌÇö¿µ | 0342-718-xxxx | ºÐ´ç±¸ | m | 1971-05-05 | 29 | 
| 6 | À̺´È¯ | 02-891-xxxx | ÇϾȵ¿ | m | 1980-06-06 | 20 | 
| 1 | ³²»ó¿í | 333-4444 | µ¿ÀÛ±¸ | m | 1971-01-01 | 29 | 
+------+--------+---------------+--------+------+------------+------+ 
6 rows in set (0.01 sec) 
    


9.3. À¯´Ð½º ½Ã°£

unix_timestamp¹®À» »ç¿ëÇÑ´Ù.

mysql> select unix_timestamp(curdate()); 
  +---------------------------+ 
  | unix_timestamp(curdate()) | 
  +---------------------------+ 
  | 934210800 | 
 +---------------------------+ 
  1 row in set (0.05 sec)
    


9.4. ¿ø°Ý DB »ç¿ëÇϱâ

A¶ó´Â ¼­¹ö¿¡ DB°¡ ÀÖ°í, 210.180.56.204¿¡¼­ ÇÁ·Î±×·¥À» µ¹¸±¶§

A¶ó´Â ¼­¿¡ÀÖ´Â mysql mysql ¿¡ ´ÙÀ½°ú °°ÀÌ ÀÔ·ÂÀ» ÇÕ´Ï´Ù.

INSERT INTO db VALUES ('210.180.56.204','dbname','user','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

INSERT INTO host VALUES ('210.180.56.204','dbname','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

INSERT INTO user VALUES ('210.180.56.204','user','passwd','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

210.180.56.204 ÀÇ ÄÄ¿¡¼­ ÇÁ·Î±×·¥À» ÇÒ¶§ ´ÙÀ½°ú °°ÀÌ ¼³Á¤À» ÇØÁÖ¸é ¿ø°Ý DB ¸¦ »ç¿ëÇÒ¼ö ÀÖ½À´Ï´Ù.

$db_server ="servername"; // DB ¼­¹ö ÁÖ¼Ò

$db_user = "root"; // DB »ç¿ëÀÚ

$db_name = ""; // DB À̸§

$db_pass = ""; // DB ¾ÏÈ£


ID
Password
Join
Love is in the offing. Be affectionate to one who adores you.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2003-08-10 11:52:29
Processing time 0.0033 sec