U E D R , A S I H C RSS

ZP Board/PHP Study/MySQL


1. 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 명ì�„ 사용하여 배열로 저장

2. 사용예제

~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 ($_POSTname != "" && $_POSTphone != "") {
mysql_connect("zeropage.org","zp2002","암호");
mysql_select_db("zp2002");
mysql_query("insert into addressbook values('$_POSTname', '$_POSTphone')");
mysql_close();
}
?>
<script language="javascript">window.location.replace("babo.php");</script>
}}} 위� 소스로 작성한 페�지�다. "주소�"


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:30
Processing time 0.0068 sec