{"id":1237,"date":"2011-08-25T06:06:06","date_gmt":"2011-08-24T21:06:06","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=1237"},"modified":"2012-02-11T00:22:22","modified_gmt":"2012-02-10T15:22:22","slug":"mysql-%e3%83%96%e3%83%a9%e3%82%a6%e3%82%b6%e3%81%8b%e3%82%89%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b%e3%83%9a%e3%83%bc%e3%82%b8%e4%bd%9c%e6%88%9003-php%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=1237","title":{"rendered":"MySQL \u30d6\u30e9\u30a6\u30b6\u304b\u3089\u64cd\u4f5c\u3059\u308b\u30da\u30fc\u30b8\u4f5c\u621003 PHP\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210"},"content":{"rendered":"<p>\u524d\u56de\u306e<\/p>\n<h3><a href=\"https:\/\/www.webcyou.com\/?p=925\">MySQL \u30d6\u30e9\u30a6\u30b6\u304b\u3089\u64cd\u4f5c\u3059\u308b\u30da\u30fc\u30b8\u4f5c\u621002 HTML\u4f5c\u6210<\/a><\/h3>\n<p>\u306e\u7d9a\u304d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u884c\u3048\u308b\u51e6\u7406\u306f<\/p>\n<p>\u203b\u00a0<strong>\u30c7\u30fc\u30bf\u306e\u53c2\u7167<\/strong><\/p>\n<p>\u203b\u00a0<strong>\u30c7\u30fc\u30bf\u306e\u691c\u7d22<\/strong><\/p>\n<p>\u203b <strong>\u30c7\u30fc\u30bf\u306e\u8ffd\u52a0<\/strong><\/p>\n<p>\u203b <strong>\u30c7\u30fc\u30bf\u306e\u66f4\u65b0<\/strong><\/p>\n<p>\u203b <strong>\u30c7\u30fc\u30bf\u306e\u524a\u9664<\/strong><\/p>\n<p>\u3068\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u305e\u308c\u306e\u51e6\u7406\u3092\u884c\u3046PHP\u30d5\u30a1\u30a4\u30eb\u306e\u7528\u610f\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>\u3068\u540c\u6642\u306bform\u8981\u7d20\u306eaction\u5c5e\u6027\u306b\u3082\u633f\u5165\u3002<\/p>\n<p><pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;form action=&quot;select.php&quot; method=&quot;post&quot;&gt;<\/pre>\n<\/p>\n<p>&nbsp;<\/p>\n<p>\u203b\u00a0<strong>\u30c7\u30fc\u30bf\u306e\u53c2\u7167<br \/>\n<\/strong>select.php<\/p>\n<p>\u203b\u00a0<strong>\u30c7\u30fc\u30bf\u306e\u691c\u7d22<br \/>\n<\/strong>search.php<\/p>\n<p>\u203b\u00a0<strong>\u30c7\u30fc\u30bf\u306e\u8ffd\u52a0<br \/>\n<\/strong>insert.php<\/p>\n<p>\u203b\u00a0<strong>\u30c7\u30fc\u30bf\u306e\u66f4\u65b0<br \/>\n<\/strong>update.php<\/p>\n<p>\u203b\u00a0<strong>\u30c7\u30fc\u30bf\u306e\u524a\u9664<br \/>\n<\/strong>delete.php<\/p>\n<p>\u3067\u306f\u3001\u307e\u305a\u5168\u4ef6\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\u306e\u53c2\u7167\u3092\u884c\u3046\u3001<\/p>\n<p>select.php\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u304b\u3089\u884c\u3044\u307e\u3059\u3002<\/p>\n<div id=\"_mcePaste\"><strong>MySQL\u306e\u3000DB\u63a5\u7d9a\u8a2d\u5b9a\u3000DB\u540d\uff0f\u30e6\u30fc\u30b6\u30fc\u540d\uff0f\u30d1\u30b9\u30ef\u30fc\u30c9<\/strong><\/div>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php define(&quot;DB_NAME&quot;,&quot;\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u540d&quot;);\r\ndefine(&quot;DB_USER&quot;,&quot;root&quot;);\r\ndefine(&quot;DB_PASS&quot;,&quot;root&quot;);?&gt;<\/pre>\n<\/p>\n<p><code style=\"font-size: 1em; letter-spacing: 0px;\">define()<\/code>\u95a2\u6570\u3092\u4f7f\u3044\u3001\u5b9a\u6570\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<p><span style=\"letter-spacing: 1px; line-height: 20px; font-family: Times; font-size: small;\">\u5b9a\u6570\u540d\u3068\u305d\u306e\u5024\u3092<\/span>DB\u63a5\u7d9a\u60c5\u5831\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>MySQL\u306b\u63a5\u7d9a<\/strong><\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php $link = mysql_connect(&quot;localhost&quot;,DB_USER,DB_PASS)\r\nor die(&quot;MySQL\u3068\u306e\u63a5\u7d9a\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot;); ?&gt;<\/pre>\n<\/p>\n<p>mysql_connect()\u95a2\u6570\u3092\u4f7f\u3044\u3001MySQL\u30b5\u30fc\u30d0\u30fc\u3078\u306e\u63a5\u7d9a\u3092\u30aa\u30fc\u30d7\u30f3\u3057\u307e\u3059\u3002<\/p>\n<p>\u3010\u30ea\u30bd\u30fc\u30b9 = mysql_connect(\u30db\u30b9\u30c8\u540d,\u30e6\u30fc\u30b6\u30fc\u540d,\u30d1\u30b9\u30ef\u30fc\u30c9)\u3011<\/p>\n<p>\u540c\u3058\u5f15\u6570\u30672\u56demysql_connect()\u3092\u30b3\u30fc\u30eb\u3057\u305f\u5834\u5408\u306f\u65b0\u898f\u306e\u30ea\u30f3\u30af\u304c\u78ba\u7acb\u3055\u308c\u308b\u306e\u3067\u306f\u306a\u304f\u3001<\/p>\n<p>\u4ee3\u308f\u308a\u306b\u3059\u3067\u306b\u30aa\u30fc\u30d7\u30f3\u3055\u308c\u305f\u30ea\u30f3\u30af\u306e\u30ea\u30f3\u30afID\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><strong>\u63a5\u7d9a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u9078\u629e<\/strong><\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php mysql_select_db(DB_NAME)\r\nor die(&quot;\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306e\u63a5\u7d9a\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot;); ?&gt;<\/pre>\n<\/p>\n<p>\u6700\u521d\u306b\u8a2d\u5b9a\u3057\u305f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u540d DB_NAME\u3068\u306e\u63a5\u7d9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u6587\u5b57\u30b3\u30fc\u30c9\u8a2d\u5b9a<\/strong><\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php mysql_query(&quot;SET NAMES utf8&quot;)\r\nor die(&quot;\u30af\u30a8\u30ea\u30fc\u306e\u5b9f\u884c\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot;); ?&gt;<\/pre>\n<\/p>\n<p>\u6587\u5b57\u30b3\u30fc\u30c9\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u30af\u30a8\u30ea\u6587\u4f5c\u6210<\/strong><\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php $query = &quot;SELECT * FROM list_t ORDER BY id_c&quot;; ?&gt;<\/pre>\n<\/p>\n<p>SELECT\u6587\u306f\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308bSQL\u6587\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u300cSELECT *\u300d \u3067\u5168\u3066\u306e\u300cFROM\u300d\u3067list_t\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u53d6\u5f97\u3001\u300cORDER BY\u300d\u3067id\u9806\u306b\u4e26\u3079\u307e\u3059\u3002<\/p>\n<pre style=\"font: normal normal normal 12px\/18px Consolas, Monaco, 'Courier New', Courier, monospace;\"> $query = \"SELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d ORDER BY \u30d5\u30a3\u30fc\u30eb\u30c9\u540d\";<\/pre>\n<p>\u5909\u6570result\u306b\u683c\u7d0d<\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php $result = mysql_query($query)\r\nor die(&quot;\u30af\u30a8\u30ea\u30fc\u306e\u5b9f\u884c\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot;);?&gt;<\/pre>\n<\/p>\n<p><strong>\u884c\u6570\u53d6\u5f97<\/strong><\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php $rows = mysql_num_rows($result); ?&gt;<\/pre>\n<\/p>\n<p>mysql_num_rows()\u95a2\u6570\u3067\u7d50\u679c\u306b\u304a\u3051\u308b\u884c\u6570\u3092\u53d6\u5f97\u3057\u3001\u5909\u6570rows\u306b\u683c\u7d0d\u3002<\/p>\n<p>\u6761\u4ef6\u5206\u5c90<\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php if($rows == 0){\r\nprint(&quot;\u8a72\u5f53\u3059\u308b\u30c7\u30fc\u30bf\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot;);\r\n}else{ ?&gt;<\/pre>\n<\/p>\n<p>\u3082\u3057\u3001\u7d50\u679c\u304c\u306a\u3044\u5834\u5408\uff08$rows == 0 \u884c\u65700\uff09\u306f\u30c7\u30fc\u30bf\u7121\u3057\u3002\u306e\u6587\u3092\u8868\u793a\u3002<br \/>\n \u30c7\u30fc\u30bf\u304c\u3042\u308b\u5834\u5408\u306f\u30c6\u30fc\u30d6\u30eb\u3092\u751f\u6210\u3002<\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;\r\n  &lt;tr class=&quot;tit&quot;&gt;\r\n    &lt;td&gt;ID&lt;\/td&gt;\r\n    &lt;td&gt;\u5e97\u540d&lt;\/td&gt;\r\n    &lt;td&gt;\u4f4f\u6240&lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n&lt;?php\r\nwhile($row = mysql_fetch_array($result)){\r\n?&gt;\r\n  &lt;tr&gt;\r\n    &lt;td&gt;&lt;?=$row&#x5B;&quot;id_c&quot;] ?&gt;&lt;\/td&gt;\r\n    &lt;td&gt;&lt;?=$row&#x5B;&quot;name_c&quot;] ?&gt;&lt;\/td&gt;\r\n    &lt;td&gt;&lt;?=$row&#x5B;&quot;add_c&quot;] ?&gt;&lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n&lt;?php\r\n}\r\nmysql_close($link);\r\n}\r\n?&gt;\r\n&lt;\/table&gt;<\/pre>\n<\/p>\n<p>while\u6587\u3067\u7d50\u679c\u306e\u6570\u3060\u3051\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3002<\/p>\n<p>mysql_fetch_array()\u95a2\u6570\u3067\u5b9f\u884c\u7d50\u679c\u3092\u914d\u5217\u306b\u683c\u7d0d\u3002<\/p>\n<p>td\u8981\u7d20\u306b\u7d50\u679c\u3092\u51fa\u529b\u3002<\/p>\n<p>\u6700\u5f8c\u3001mysql_close($link);\u3067\u63a5\u7d9a\u3092\u7d42\u4e86\u3055\u305b\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306e MySQL \u30d6\u30e9\u30a6\u30b6\u304b\u3089\u64cd\u4f5c\u3059\u308b\u30da\u30fc\u30b8\u4f5c\u621002 HTML\u4f5c\u6210 \u306e\u7d9a\u304d\u306b\u306a\u308a\u307e\u3059\u3002 \u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u884c\u3048\u308b\u51e6\u7406\u306f \u203b\u00a0\u30c7\u30fc\u30bf\u306e\u53c2\u7167 \u203b\u00a0\u30c7\u30fc\u30bf\u306e\u691c\u7d22 \u203b \u30c7\u30fc\u30bf\u306e\u8ffd\u52a0 \u203b \u30c7\u30fc\u30bf\u306e\u66f4\u65b0 \u203b \u30c7\u30fc\u30bf\u306e\u524a\u9664 \u3068\u306a\u3063\u3066\u304a\u308a\u307e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[180,173],"class_list":["post-1237","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql","tag-php"],"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/1237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1237"}],"version-history":[{"count":10,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/1237\/revisions"}],"predecessor-version":[{"id":1241,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/1237\/revisions\/1241"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}