½ñÀÒ/¼ÂÎã¤Ç¿È¤Ë¤Ä¤±¤ë¡ªMySQL¡ßPHP¤Ë¤è¤ëËܳÊWeb¡ÝDB¥·¥¹¥Æ¥àÆþÌç
Last-modified: 2018-11-14 (¿å) 15:24:17 (2214d)
2006-09-20¡Á
½ñÀÒ¤ÎWeb¥Ú¡¼¥¸
http://www.gihyo.co.jp/books/syoseki.php/4-7741-1730-7
chap3 †
sample1 †
formÆþÎÏ¥Ú¡¼¥¸¢ª³Îǧ¥Ú¡¼¥¸¢ªÅÐÏ¿´°Î»¥Ú¡¼¥¸ ¤Î´ðËÜ
ÆþÎÏÃͤΥÁ¥§¥Ã¥¯¤Ï̵¤·
- index.html ... formÆþÎÏ¥Ú¡¼¥¸
- confirm.php ... ³Îǧ¥Ú¡¼¥¸
- hidden¤òÍѤ¤¤¿ÆþÎÏÃͤμõ¤±ÅϤ·ÊýË¡
- regist.php ... ÅÐÏ¿´°Î»¥Ú¡¼¥¸
- MySQL¥¢¥¯¥»¥¹ÊýË¡
sample2 †
- index.html ... formÆþÎÏ¥Ú¡¼¥¸
- confirm.php ... ³Îǧ¥Ú¡¼¥¸
¼¡¤Î£²¥Õ¥¡¥¤¥ë¤òrequire¤·¤Æ¤¤¤Þ¤¹¡£- function.php ... gpc_stripslashes, gpc_addslashes, secho¤ÎÄêµÁ
- check_values.php ... ³ÆpostÃͤò¥Á¥§¥Ã¥¯¤·¡¢¥¨¥é¡¼¤ÎÏ¢ÁÛÇÛÎó($error['fname']Åù)¤òºîÀ®¤¹¤ë½èÍý
Shift JIS¤ÇPHP¥³¡¼¥É¤ò½ñ¤¯¾ì¹ç¡¢ ¡Ömb_regex_encoding("Shift_JIS"); ¡×¤È½ñ¤¤¤Æ¤ª¤«¤Ê¤¤¤È¡¢¡Ömb_ereg("^[¥¡-¥ö¡¼]+$", $fname)¡×¤È¤¤¤Ã¤¿Ê¸¤Ç¡¢ ¡Ömbregex compile err: empty char-class¡×¤È¤¤¤Ã¤¿·Ù¹ð¤¬½Ð¤ë¾ì¹ç¤¬Í¤ê¤Þ¤¹¡£ ¡Ê¡Ö¡¼¡×¤ÎShift JIS¥³¡¼¥É¤Ï¡¢0x815B¤Ç¡¢¡Ö5B¡×¤¬¡Ö[¡×¤Î¤¿¤á·Ù¹ð¤¬½Ð¤Þ¤¹¡Ë
- regist.php ... ÅÐÏ¿´°Î»¥Ú¡¼¥¸
- ºÆ¥Á¥§¥Ã¥¯¤Î¤¿¤á¡¢¾å¤Î£²¥Õ¥¡¥¤¥ë¤òrequire¤·¤Æ¤¤¤Þ¤¹¡£
- ¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤ò¥Æ¥ó¥×¥ì¡¼¥È¤È¤·¤¿¥á¡¼¥ëÁ÷¿®¥µ¥ó¥×¥ë¤Ç¤¹¡£
- mail.txt ... regist.php¤«¤é»ÈÍѤµ¤ì¤ë¡¢ÅÐÏ¿´°Î»¥á¡¼¥ë¥Æ¥ó¥×¥ì¡¼¥È¤Ç¤¹¡£
- downlist.php ... ¥À¥¦¥ó¥í¡¼¥É²èÌÌ
- MySQL¤ÇÁí·ï¿ô¤òÄ´¤Ù¤Æ¡¢É½¼¨¤·¤Æ¤¤¤Þ¤¹¡£
$iCount = mysql_query("SELECT COUNT(*) AS NUM FROM ¥Æ¡¼¥Ö¥ë̾");
- <a href="download.php?...">1-100</a>¤È¤¤¤Ã¤¿¡¢¤É¤ÎÈϰϤò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤«¤òɽ¤¹¥ê¥ó¥¯¤Îµ½ÒÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
- download.php ... tabʬ³ä¥Ç¡¼¥¿¤Î¥À¥¦¥ó¥í¡¼¥É¥×¥í¥°¥é¥à
- ¥Ö¥é¥¦¥¶¤Çtab¥Ç¡¼¥¿¤Î¥À¥¦¥ó¥í¡¼¥É¥À¥¤¥¢¥í¥°¤ò½Ð¤¹ÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
$strFileName = ($_GET['iStartIndex'] + 1) . "-" . ($_GET['iStartIndex'] + $_GET['iDownloadCount']) . ".tab"; header("Content-Type: text/tab-separated-values"); header("Content-Disposition: attachment; filename=$strFileName"); while($row = mysql_fetch_array($rs)) { $strRow = $row['iID'] . "\t" . $row['strName']. "\r\n"; echo mb_convert_encoding($strRow, "SJIS"); }
- MySQL¤Ç»ØÄêÈϰϤΥǡ¼¥¿¤ò¼èÆÀ¤¹¤ëÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
$dbResult = mysql_query("SELECT * FROM ¥Æ¡¼¥Ö¥ë̾ LIMIT " . $_GET['iStartIndex'] . ", " . $_GET['iDownloadCount']);
- ¥Ö¥é¥¦¥¶¤Çtab¥Ç¡¼¥¿¤Î¥À¥¦¥ó¥í¡¼¥É¥À¥¤¥¢¥í¥°¤ò½Ð¤¹ÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
- MySQL¤ÇÁí·ï¿ô¤òÄ´¤Ù¤Æ¡¢É½¼¨¤·¤Æ¤¤¤Þ¤¹¡£
sample3 †
- index.html ... formÆþÎÏ¥Ú¡¼¥¸
sample2¤È¤Þ¤Ã¤¿¤¯Æ±¤¸¤Ç¤¹¡£ - index.php ... formÆþÎÏ¥Ú¡¼¥¸PHPÈÇ
POSTÃͤò¼õ¤±¼è¤ê¡¢formÁ°²óÆþÎÏÃͤòÉüµ¢¤·¤Þ¤¹¡£
index.html¤È¼¡¤Î£³ÅÀ¤¬°ã¤¤¤Þ¤¹¡£
- <?php
session_start();
require("function.php");
require("check_values.php");
$_SESSION['register'] = 0;
?> - <form method="post" action="confirm.php?<?=SID?>">
- <input type="text" name="name" value="<?php secho($name) ?>" /><br />
- <?php
- confirm.php ... ³Îǧ¥Ú¡¼¥¸
¼¡¤Î¤è¤¦¤Ë¥»¥Ã¥·¥ç¥ó¤òÍѤ¤¤¿¥»¥¥å¥ê¥Æ¥£¥³¡¼¥É¤¬Äɲ䵤ì¤Æ¤¤¤Þ¤¹¡£- session_start();
- $_SESSION['register']¤¬Ì¤ÄêµÁ¤Þ¤¿¤Ï£°°Ê³°¤Î¾ì¹ç¡¢error.html¤òɽ¼¨¤·¤Þ¤¹¡£
- ¡ÖÌá¤ë¡×¤ò²¡¤·¤¿¤È¤¤Ë¡¢¡Öaction="index.php?<?=SID?>"¡×¤ò¸Æ¤Ó½Ð¤·¡¢ÆþÎÏÃͤòÊÝ»ý¤·¤¿ÆþÎϲèÌ̤òÉüµ¢¤µ¤»¤Æ¤¤¤Þ¤¹¡£
- regist.php ... ÅÐÏ¿´°Î»¥Ú¡¼¥¸
¼¡¤Î¤è¤¦¤Ë¥»¥Ã¥·¥ç¥ó¤òÍѤ¤¤¿¥»¥¥å¥ê¥Æ¥£¥³¡¼¥É¤¬Äɲ䵤ì¤Æ¤¤¤Þ¤¹¡£- session_start();
- $_SESSION['register']¤¬Ì¤ÄêµÁ¤Þ¤¿¤Ï£°°Ê³°¤Î¾ì¹ç¡¢error.html¤òɽ¼¨¤·¤Þ¤¹¡£
- MySQL¤Ç¥Æ¡¼¥Ö¥ë¤ò¥í¥Ã¥¯¤·¤Æ¤¤¤Þ¤¹¡£
mysql_query("lock tables members write"); - Ʊ¤¸ÅŻҥ᡼¥ë¥¢¥É¥ì¥¹¤¬ÅÐÏ¿ºÑ¤ß¤Î¾ì¹ç¡¢·Ù¹ð¤òɽ¼¨¤·¤Æ¡¢ÅÐÏ¿¤òÈ´¤±¤Þ¤¹¡£
- MySQL¤ËÅÐÏ¿À®¸ù¸å¡¢¥»¥Ã¥·¥ç¥ó¤ÎÃͤò£²¤Ë¤·¤Æ¤¤¤Þ¤¹¡£
chap4 †
chap4.sql.txt
sample1 †
- regist.php ... ÆþÎÏ
- regist_confirm.php ... ³Îǧ
- regist_done.php ... ÅÐÏ¿´°Î»
- check_values.php ... ÆþÎÏ¥Á¥§¥Ã¥¯
- define.php ... ÄêµÁ¥Õ¥¡¥¤¥ë
- error.html ... ¥¨¥é¡¼É½¼¨
- list_simple.php
- MySQL¤Ç¿·¤·¤¤½ç¤Ë¼è¤ê½Ð¤¹SRL¤¬Ê¬¤«¤ê¤Þ¤¹¡£
- php¥×¥í¥°¥é¥à¤ÎÃæ¤Ç¡¢html¤ÎÃæ¤Ë¡Ö<?php ?>¡×¤ò¤Á¤ê¤Ð¤á¤Æ¡¢¥ë¡¼¥×¤ò¹½À®¤·¡¢¥Æ¡¼¥Ö¥ë¹Ô¤ò½ñ¤¯ÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
- list.php
- ¥»¥¥å¥ê¥Æ¥£ÍѤ˥»¥Ã¥·¥ç¥óÊÑ¿ô¤ò½é´ü²½¤¹¤ë¥³¡¼¥É¤¬Æþ¤Ã¤Æ¤¤¤Þ¤¹¡£
session_start(); $_SESSION['register'] = 0; $_SESSION['modify'] = 0; $_SESSION['delete'] = 0;
- ¥Ú¡¼¥¸¥¤¥ó¥Ç¥Ã¥¯¥¹¤òget¤Ç¼õ¤±¼è¤ê¡¢¡Ö¼¡¤Î??·ï¡×¡ÖÁ°¤Î??·ï¡×¤Î¥ê¥ó¥¯¤Ç¼«¿È¤ò¸Æ¤Ó½Ð¤·¡¢²èÌ̤ò¹¹¿·¤¹¤ëÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
- ¼¡¤Î³Æµ¡Ç½¤Îphp¥×¥í¥°¥é¥à¤ò¸Æ¤Ó½Ð¤¹¥ê¥ó¥¯¤¬Í¤ê¤Þ¤¹¡£
¥ê¥ó¥¯¹àÌÜ Èô¤ÓÀèphp µ¡Ç½ ¿·µ¬ÅÐÏ¿ index.php ¥È¥Ã¥×¥Ú¡¼¥¸¤ËÌá¤ë ÊÔ½¸ modify.php Áª¤ó¤À¹Ô¤ÎÊÔ½¸ ºï½ü delete_confirm.php Áª¤ó¤À¹Ô¤Îºï½ü
- ¥»¥¥å¥ê¥Æ¥£ÍѤ˥»¥Ã¥·¥ç¥óÊÑ¿ô¤ò½é´ü²½¤¹¤ë¥³¡¼¥É¤¬Æþ¤Ã¤Æ¤¤¤Þ¤¹¡£
- list_sort.php
- delete_confirm.php
- delete_done.php
- function.php
- modify.php
- modify_confirm.php
- modify_done.php
sample2 †
http://papuu.jp/develop/bk/0001/chap4/sample2/index.html
- check_values.php
- define.php
- delete_confirm.php
- delete_done.php
- error.html
- function.php
- list.php
- modify.php
- modify_confirm.php
- modify_done.php
- news.html
- news.php
- news2.php
- news_create.php
- news_template.html
- regist.php
- regist_confirm.php
- regist_done.php
- search.html
chap5 †
sample1 †
³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (¡ó¿ôÃͤǷë²Ìɽ¼¨)
- index.php ... ¥é¥¸¥ª¥Ü¥¿¥ó¤ÇÁªÂò¤·¡¢result.php¤ò¸Æ¤Ó½Ð¤·¤Þ¤¹¡£
- ¥»¥Ã¥·¥ç¥ó¤Ë¤è¤ë£²½ÅÅêɼËɻߵ¡Ç½¤¬Í¤ê¤Þ¤¹¡£
- result.php ... ÅÐÏ¿¡¦·ë²Ì²èÌÌɽ¼¨
- MySQL¤ÇÅêɼ¤òÅÐÏ¿¤·¤Þ¤¹¡£¡Ê¸«¤ë¤À¤±¤Î¾ì¹ç¤Ï¡¢ÅÐÏ¿¤·¤Þ¤»¤ó¡Ë
- MySQL¤ÇÅêɼ·ë²Ì¼èÆÀ¤·¤Þ¤¹¡£
- ¥»¥Ã¥·¥ç¥ó¤Ë¤è¤ë£²½ÅÅêɼËɻߵ¡Ç½¤¬Í¤ê¤Þ¤¹¡£
sample2 †
³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (dot.png¤òimg¥¿¥°¤Îwidth, height°À¤Ç°ú¤±ä¤Ð¤·¤Æ¡¢·ë²Ìɽ¼¨)
sample3 †
³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (£·¿§¤Îpng²èÁü°ú¤±ä¤Ð¤·¤Ç¡¢ÀѤ߾夲¥°¥é¥Õ¤Ç·ë²Ìɽ¼¨
sample4 †
³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (±ß¥°¥é¥Õ¤Ç·ë²Ìɽ¼¨)
sample5 †
³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (±ß¥°¥é¥Õ¤Ç·ë²Ìɽ¼¨)
- index.php
¥³¥á¥ó¥ÈÆþÎÏÍóÄɲà - result.php
- 1.png¡Á7.png
- rs.png
- error.html
- delete_confirm.php
- delete_done.php
- list.php
sample6 †
³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (±ß¥°¥é¥Õ¤Ç·ë²Ìɽ¼¨)
- index.php
sample5¤È¤Þ¤Ã¤¿¤¯Æ±¤¸ - result.php
- 1.png¡Á7.png
- rs.png
- error.html
- delete_confirm.php
- delete_done.php
- list.php
chap6 †
sample1 †
sample2 †
sample3 †
sample4 †
chap7 †
sample1 †
ÊÙ¶¯¤·¤¿¤³¤È †
- <input ... /><br />¤Î¤è¤¦¤Ë¡¢ÊĤ¸¤Ê¤¤¥¿¥°¤ÎºÇ¸å¤Ï¡¢É¬¤º¥¹¥é¥Ã¥·¥å¤òÆþ¤ì¤ë¡£
- PHP¤Ç¤Ïʸ»úÎó¤ÎÀÚ¤ìÌܤ¬Ê¬¤«¤ê¤Ë¤¯¤¤¤Î¤Ç¡¢Ê¸»úÎó¤òÏ¢·ë¤¹¤ë¥É¥Ã¥È¤ÎÁ°¸å¤Ï¡¢¥¹¥Ú¡¼¥¹¤òÆþ¤ì¤¿¤Û¤¦¤¬¸«¤ä¤¹¤½¤¦¡£
- SERVER_NAME¤ÈHTTP_HOST¤ÎÈæ³Ó
$_SERVER["SERVER_NAME"]; localhost Ãͤò¼èÆÀ¤·¤Ê¤ó¤é¤«¤Î·Á¤ÇÍøÍѤ¹¤ë¾ì¹ç¤Ë»ÈÍѤ·¤Þ¤¹¡£ ¥ê¥¯¥¨¥¹¥È»þ¤Î host:〜 ¤ò»È¤¦¤â¤Î¤Î¡¢»ØÄ̵꤬¤¤¾ì¹ç¤Ï httpd.confÅù¤Ëµ½Ò¤·¤¿ServerName¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤¬¥Ç¥Õ¥©¥ë¥È¤Ç»È¤ï¤ì¤Þ¤¹¡£htmlentities¤Ë¤è¤Ã¤Æ¥¨¥¹¥±¡¼¥×¤µ¤ì¤ë¤è¤¦¤Ç¤¹¡£ $_SERVER["HTTP_HOST"]; localhost:50000 ¥ê¥¯¥¨¥¹¥È¥Ø¥Ã¥À¡¼¤ÎÃͤò¤½¤Î¤Þ¤Þ¼è¤ê¤¿¤¤¾ì¹ç¤Ë»ÈÍѤ·¤Þ¤¹¡£ ¥ê¥¯¥¨¥¹¥È»þ¤Ë host:〜 ¤Ç»ØÄꤷ¤¿Ãͤ¬ÊÖ¤µ¤ì¤Þ¤¹¡£ - php.ini¤ÎÆüËܸ쥳¡¼¥ÉÀßÄê
ÆüËܸì¤ÎÀßÄ꤬¹ç¤Ã¤Æ¤¤¤Ê¤¤¤È¡¢¡ÖParse error:¡×¤È¤¤¤Ã¤¿¥¨¥é¡¼¤¬½Ð¤ë¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£º£²ó¤¹¤Ù¤ÆShift JIS¤ËÅý°ì¤·¤Þ¤¹¤Î¤Ç¡¢¼¡¤Î¤è¤¦¤ËÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£
C:\Program Files\xampp\apache\bin\php.ini
Directive default changed mbstring.detect_order no value mbstring.encoding_translation Off mbstring.func_overload 0 mbstring.http_input pass mbstring.http_output pass mbstring.internal_encoding no value mbstring.language neutral mbstring.strict_detection Off mbstring.substitute_character no value output_handler = mb_output_handler default_charset = "Shift_JIS" magic_quotes_gpc = Off
- id¤Î¹àÌܤò¡Öauto_increment¡×¤Ë¤·¤Ê¤¤¤È¡¢insert¤ÇMySQL¤ËÄɲ䷤Ƥ⡢ÄɲäǤ¤Ê¤¤¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£
phpMyAdmin¤Ç¡Öauto_increment¡×¤ËÀßÄꤹ¤ëÊýË¡¤Ï¡¢¡Ö¤½¤Î¾¡×¤ÇÁªÂò¤·¤Þ¤¹¤Î¤Ç¡¢Ãí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£ - ¸å¤«¤éphpMyAdmin¤Çid¤òauto_increment¤ËÊѤ¨¤è¤¦¤È¤·¤Æ¡¢¼¡¤Î¥¨¥é¡¼¤È¤Ê¤ê¤Þ¤·¤¿¡£ ¡ÖDuplicate entry '1' for key 1 ¡× iId¤ò¤¤¤Ã¤¿¤óºï½ü¤·¤Æ¤«¤éÄɲä·¤¿¤é¡¢Âç¾æÉפǤ·¤¿¡£