{"id":1334,"date":"2011-11-20T03:58:32","date_gmt":"2011-11-19T18:58:32","guid":{"rendered":"http:\/\/codaholic.org\/?p=1334"},"modified":"2022-01-01T15:55:51","modified_gmt":"2022-01-01T06:55:51","slug":"phppdo%e3%82%af%e3%83%a9%e3%82%b9%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ab%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/codaholic.org\/?p=1334","title":{"rendered":"[PHP] PDO \u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b"},"content":{"rendered":"<p>\u3053\u308c\u307e\u3067P HP \u304b\u3089 MySQL \u306b\u63a5\u7d9a\u3059\u308b\u3068\u304d\u306f PEAR \u306e MDB2 \u3092\u4f7f\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001PEAR \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u74b0\u5883\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3059\u308b\u306b\u306f\u4f55\u304b\u65b9\u6cd5\u306f\u306a\u3044\u306e\u304b\u3068\u601d\u3044\u8abf\u3079\u307e\u3057\u305f\u3002\u3059\u308b\u3068 PDO \u30af\u30e9\u30b9\u3068\u3044\u3046\u4fbf\u5229\u305d\u3046\u306a\u3082\u306e\u3092\u898b\u3064\u3051\u307e\u3057\u305f\u3002<\/p>\n<p><!--more--><\/p>\n<p>PDO \u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3059\u308c\u3070\u3001\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u3080\u3053\u3068\u3082\u306a\u304f\u3044\u304d\u306a\u308a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3059\u308b\u6a5f\u80fd\u3092\u5229\u7528\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001PDO \u30af\u30e9\u30b9\u304c\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u4e88\u3081\u52d5\u4f5c\u3055\u305b\u305f\u3044\u30b5\u30fc\u30d0\u30fc\u3067\u52d5\u304b\u3057\u3066\u307f\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002ServerQueen \u306e\u5171\u6709\u30b5\u30fc\u30d0\u30fc\u3001\u30ed\u30ea\u30dd\u30c3\u30d7\u306e\u5171\u6709\u30b5\u30fc\u30d0\u30fc\u3067\u52d5\u304d\u307e\u3057\u305f\u306e\u3067\u4f59\u7a0b\u53e4\u3044\u74b0\u5883\u3067\u306a\u3051\u308c\u3070\u5927\u4e08\u592b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u306f MySQL \u306b\u63a5\u7d9a\u3057\u3001data \u30c6\u30fc\u30d6\u30eb\u304b\u3089\u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3057\u305f\u3042\u3068\u3001url \u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5185\u5bb9\u30921\u884c\u3054\u3068\u306b\u6539\u884c\u3057\u3066\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-php\">&lt;?php\n    $pdo = new PDO('mysql:host=HOSTNAME; dbname=DATABASENAME', 'USERNAME', 'PASSWORD');\n    $results = $pdo-&gt;query('SELECT * FROM data');\n    while($row = $results-&gt;fetch(PDO::FETCH_ASSOC)){\n        echo $row['url'] . '&lt;br \/&gt;';\n    }\n    $pdo = null;\n?&gt;\n<\/code><\/pre>\n<p><strong>2\u884c\u76ee<\/strong><br \/>\nPDO\u30af\u30e9\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30db\u30b9\u30c8\u540d(HOSTNAME\u306e\u3068\u3053\u308d\u3002\u591a\u304f\u5834\u5408localhost\u3002)\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u540d(DATABASENAME\u306e\u3068\u3053\u308d)\u3001\u30e6\u30fc\u30b6\u30fc\u540d(USERNAME\u306e\u3068\u3053\u308d)\u3001\u30d1\u30b9\u30ef\u30fc\u30c9(PASSWORD\u306e\u3068\u3053\u308d)\u3092\u6e21\u3057\u3066\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><strong>3\u884c\u76ee<\/strong><br \/>\nquery\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3068SQL\u3092\u9001\u4fe1\u3067\u304d\u307e\u3059\u3002\u554f\u3044\u5408\u308f\u305b\u306e\u7d50\u679c\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u8fd4\u3063\u3066\u304d\u307e\u3059\u306e\u3067\u3001$results\u306b\u4ee3\u5165\u3057\u307e\u3059\u3002<\/p>\n<p><strong>4\u884c\u76ee<\/strong><br \/>\n\u7d50\u679c\u3068\u3057\u3066\u53d7\u3051\u3068\u3063\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306efetch\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3068\u30c7\u30fc\u30bf\u30921\u884c\u3054\u3068\u306b\u53d6\u308a\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002fetch\u30e1\u30bd\u30c3\u30c9\u306b\u5f15\u6570\u3068\u3057\u3066PDO::FETCH_ASSOC\u3092\u6e21\u3059\u3068\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u3092\u30ad\u30fc\u3068\u3057\u305f\u9023\u60f3\u914d\u5217\u304c\u8fd4\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong>5\u884c\u76ee<\/strong><br \/>\n\u5f93\u3063\u3066$row\u306b\u306f\u9023\u60f3\u914d\u5217\u3067\u30c7\u30fc\u30bf\u304c\u4fdd\u5b58\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001url\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30c7\u30fc\u30bf\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3044\u5834\u5408\u306f\u3001$row[&#8216;url&#8217;]\u3068\u3057\u307e\u3059\u3002<\/p>\n<p><strong>7\u884c\u76ee<\/strong><br \/>\n\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u3092\u9589\u3058\u308b\u306b\u306f\u3001\u63a5\u7d9a\u6642\u306b\u4f5c\u6210\u3057\u305f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e$pdo\u306bnull\u3092\u4ee3\u5165\u3059\u308b\u304b\u3001unset($pdo)\u3068\u3057\u3066\u524a\u9664\u3092\u3059\u308c\u3070\u9589\u3058\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u308c\u307e\u3067P HP \u304b\u3089 MySQL \u306b\u63a5\u7d9a\u3059\u308b\u3068\u304d\u306f PEAR \u306e MDB2 \u3092\u4f7f\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001PEAR \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u74b0\u5883\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3059\u308b\u306b\u306f\u4f55\u304b\u65b9\u6cd5\u306f\u306a\u3044\u306e\u304b\u3068\u601d\u3044\u8abf\u3079\u307e\u3057\u305f\u3002\u3059\u308b\u3068 PDO  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[4],"tags":[188,244],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8gd1W-lw","_links":{"self":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1334"}],"collection":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1334"}],"version-history":[{"count":3,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1334\/revisions"}],"predecessor-version":[{"id":2600,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1334\/revisions\/2600"}],"wp:attachment":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}