[[TableOfContents]] = MySQL 사용하기 = * mysql_connect, mysql_close, mysql_query, mysql_affected_rows, mysql_num_rows, mysql_fetch_row, mysql_fetch_array * mysql_connect ("ì ‘ì†í• 서버주소", "ì•„ì´ë””", "패스워드"); * mysql ì— ì ‘ì†í•œë‹¤. * mysql_close(); * mysql ì ‘ì†ì„ ëŠëŠ”다. * mysql_query("문장 ëì˜ ì„¸ë¯¸ì½œë¡ ì—†ì´ ì‹¤í–‰í• ëª…ë ¹ì–´ ìž…ë ¥"); * mysql 함수를 실행한다. * ex) $result = mysql_db_query("zp2002","select * from addressbook order by binary name"); * $result 는 변수ì´ë¦„, ì‹¤í–‰ê²°ê³¼ì˜ identifier를 ë°›ìŒ * mysql_affected_rows * mysql_num_rows * mysql_fetch_row(ì‹¤í–‰ê²°ê³¼ì˜ identifier); * ì‹¤í–‰ê²°ê³¼ì˜ identifierì˜ ë‚´ìš©ì„ ë°°ì—´ë¡œ ì €ìž¥ * ex) $row = mysql_fetch_array($result); * mysql_fetch_array(ì‹¤í–‰ê²°ê³¼ì˜ identifier); * mysql_fetch_row ì˜ í™•ìž¥íŒ * ì‹¤í–‰ê²°ê³¼ì˜ identifierì˜ ë‚´ìš©ì„ field ëª…ì„ ì‚¬ìš©í•˜ì—¬ ë°°ì—´ë¡œ ì €ìž¥ = ì‚¬ìš©ì˜ˆì œ = {{{~cpp ì°¸ê³ ë¡œ 다ìŒì˜ ëª…ë ¹ì–´ë“¤ì€ ê°™ì€ ì‹¤í–‰ê²°ê³¼ë¥¼ 보여준다.. 1. mysql_select_db("database1"); mysql_query("select * from table1 by order name"); 2. mysql_query("use database1"); mysql_query("select * from table1 by order name"); 3. mysql_db_query("database1", "select * from table1 by order name"); }}} 다ìŒì€ 간단하게 만들어 본 ì£¼ì†Œë¡ ì†ŒìŠ¤ì´ë‹¤..{{{~cpp <!--babo.php--> <html> <head> <title> ì£¼ì†Œë¡ </title> </head> <body> <table border=1 cellpadding=2> <tr align=center> <td> ì´ë¦„ </td> <td width=120> ì „í™”ë²ˆí˜¸ </td> </tr> <?php mysql_connect ("165.194.17.15", "zp2002", "암호"); $result = mysql_db_query("zp2002","select * from addressbook order by binary name"); while($row = mysql_fetch_array($result)) { echo "<tr> <td>", $row["name"], "</td><td align=center>", $row["phone"], "</td> </tr>"; } mysql_close(); ?> </table> <FORM method="POST" action="save.php" > ì´ë¦„ <INPUT type="text" name="name" value="" size=10 maxlength=10> ì „í™”ë²ˆí˜¸ <INPUT type="text" name="phone" value="" size=15 maxlength=15> <INPUT type="submit" value="ìž…ë ¥" size=5> </FORM> <font size=2 color=red>※ ì´ë¦„ê³¼ ì „í™”ë²ˆí˜¸ë¥¼ ëª¨ë‘ ìž…ë ¥í•´ì•¼ ì €ìž¥ì´ ë©ë‹ˆë‹¤. <br> ì´ë¦„ 10bytes, ì „í™”ë²ˆí˜¸ 15bytes ì´ë‚´ë¡œ ìž…ë ¥í•´ì£¼ì„¸ìš”. </font> </body> </html> }}}{{{~cpp <!--save.php--> <?php if ($_POST[name] != "" && $_POST[phone] != "") { mysql_connect("zeropage.org","zp2002","암호"); mysql_select_db("zp2002"); mysql_query("insert into addressbook values('$_POST[name]', '$_POST[phone]')"); mysql_close(); } ?> <script language="javascript">window.location.replace("babo.php");</script> }}} ìœ„ì˜ ì†ŒìŠ¤ë¡œ 작성한 페ì´ì§€ì´ë‹¤. [http://165.194.17.15/~bestjn83/babo.php "주소ë¡"] ---- [PHP]