{"id":832,"date":"2025-08-05T16:22:28","date_gmt":"2025-08-05T07:22:28","guid":{"rendered":"https:\/\/nexive.tech\/?p=832"},"modified":"2025-08-05T16:22:28","modified_gmt":"2025-08-05T07:22:28","slug":"%e3%80%90%e3%82%b5%e3%82%af%e3%83%83%e3%81%a8%e8%a7%a3%e8%aa%ac%e3%80%91php-%e3%83%97%e3%83%ac%e3%83%bc%e3%82%b9%e3%83%9b%e3%83%ab%e3%83%80%e3%81%a7%e5%ae%89%e5%85%a8%e3%81%abselect%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/nexive.tech\/?p=832","title":{"rendered":"\u3010\u30b5\u30af\u30c3\u3068\u89e3\u8aac\u3011PHP \u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3067\u5b89\u5168\u306bSELECT\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u5bfe\u7b56\u3068\u3057\u3066\u3001\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3092\u4f7f\u3063\u305fSELECT\u6587\u306e\u66f8\u304d\u65b9\u3092\u89e3\u8aac<\/li>\n\n\n\n<li><code>PDO<\/code>\u306b\u3088\u308b\u5b9f\u88c5\u3092\u4e2d\u5fc3\u306b\u3001\u30d0\u30a4\u30f3\u30c9\u65b9\u6cd5\u306e\u9055\u3044\u3084\u6ce8\u610f\u70b9\u3092\u7d39\u4ecb<\/li>\n\n\n\n<li>\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306e\u7a2e\u985e\u3068\u4f7f\u3044\u5206\u3051\u3092\u5b9f\u52d9\u8996\u70b9\u3067\u6574\u7406<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. PHP\u306e\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306b\u3088\u308bSELECT\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>PHP\u3067SQL\u3092\u6271\u3046\u969b\u3001\u52d5\u7684\u306a\u5024\u3092\u76f4\u63a5\u30af\u30a8\u30ea\u6587\u5b57\u5217\u306b\u57cb\u3081\u8fbc\u3080\u3068\u3001SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u306e\u30ea\u30b9\u30af\u304c\u751f\u3058\u307e\u3059\u3002\u3053\u308c\u3092\u56de\u907f\u3059\u308b\u4ee3\u8868\u7684\u306a\u624b\u6cd5\u304c\u300c\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u300d\u306e\u4f7f\u7528\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3068\u306f\u3001SQL\u6587\u5185\u306e\u5024\u306e\u4ee3\u308f\u308a\u306b\u8a18\u53f7\u3092\u5165\u308c\u3001\u5f8c\u304b\u3089\u5b89\u5168\u306b\u5024\u3092\u30d0\u30a4\u30f3\u30c9\u3059\u308b\u3053\u3068\u3067\u3001SQL\u306e\u69cb\u9020\u3068\u30c7\u30fc\u30bf\u306e\u5206\u96e2\u3092\u5b9f\u73fe\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002PHP\u3067\u306f<code>PDO<\/code>\uff08PHP Data Objects\uff09\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u4ed8\u304d\u306e\u30d7\u30ea\u30da\u30a2\u30c9\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u7c21\u6f54\u306b\u6271\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u7279\u306bSELECT\u6587\u306f\u5916\u90e8\u5165\u529b\u306b\u4f9d\u5b58\u3059\u308b\u6a5f\u4f1a\u304c\u591a\u3044\u305f\u3081\u3001\u5b89\u5168\u306a\u66f8\u304d\u65b9\u306f\u57fa\u672c\u4e2d\u306e\u57fa\u672c\u3067\u3059\u3002\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306e\u4f7f\u3044\u65b9\u306f\u3001\u5b9f\u52d9\u3067\u306e\u30c7\u30fc\u30bf\u53d6\u5f97\u51e6\u7406\u306b\u304a\u3044\u3066\u3001\u5805\u7262\u6027\u30fb\u4fdd\u5b88\u6027\u306e\u89b3\u70b9\u304b\u3089\u3082\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u8a73\u7d30\u89e3\u8aac<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u57fa\u672c\uff1a\u540d\u524d\u4ed8\u304d\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3067\u306eSELECT<\/h3>\n\n\n\n<p>\u30e6\u30fc\u30b6ID\u3092\u3082\u3068\u306b\u8a72\u5f53\u30e6\u30fc\u30b6\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u4f8b\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>&lt;?php\n\/\/ DB\u63a5\u7d9a\uff08\u4f8b\uff1aMySQL\uff09\n$pdo = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8mb4', 'user', 'password');\n\n\/\/ \u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3092\u542b\u3080\u30af\u30a8\u30ea\n$sql = \"SELECT * FROM users WHERE id = :id\";\n$stmt = $pdo->prepare($sql);\n\n\/\/ \u5024\u306e\u30d0\u30a4\u30f3\u30c9\n$stmt->bindValue(':id', 5, PDO::PARAM_INT);\n$stmt->execute();\n\n\/\/ \u7d50\u679c\u53d6\u5f97\n$result = $stmt->fetch(PDO::FETCH_ASSOC);\nprint_r($result);\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">&lt;?php<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ DB\u63a5\u7d9a\uff08\u4f8b\uff1aMySQL\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$pdo<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #569CD6\">new<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">PDO<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;mysql:host=localhost;dbname=testdb;charset=utf8mb4&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;user&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;password&#39;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3092\u542b\u3080\u30af\u30a8\u30ea<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$sql<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #D4D4D4\">*<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #CE9178\"> users <\/span><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #CE9178\"> id <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\"> :id&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$pdo<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">prepare<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$sql<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u5024\u306e\u30d0\u30a4\u30f3\u30c9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">bindValue<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;:id&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #4EC9B0\">PDO<\/span><span style=\"color: #D4D4D4\">::PARAM_INT);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">execute<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u7d50\u679c\u53d6\u5f97<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$result<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">fetch<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">PDO<\/span><span style=\"color: #D4D4D4\">::FETCH_ASSOC);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print_r<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$result<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>:id<\/code>\u304c\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\uff08\u540d\u524d\u4ed8\u304d\uff09\u3067\u3059\u3002<\/li>\n\n\n\n<li><code>bindValue()<\/code>\u3067\u306f\u578b\u6307\u5b9a\u3082\u53ef\u80fd\uff08\u4f8b\uff1a<code>PDO::PARAM_INT<\/code>\uff09\u3002<\/li>\n\n\n\n<li><code>fetch()<\/code>\u30671\u884c\u5206\u306e\u7d50\u679c\u3092\u53d6\u5f97\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u756a\u53f7\u4ed8\u304d\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306e\u4f7f\u7528<\/h3>\n\n\n\n<p>\u540c\u69d8\u306eSELECT\u6587\u3092\u3001\u756a\u53f7\u4ed8\u304d\u3067\u66f8\u304f\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$sql = \"SELECT * FROM users WHERE id = ?\";\n$stmt = $pdo->prepare($sql);\n$stmt->execute(&#91;5&#93;);\n$result = $stmt->fetch(PDO::FETCH_ASSOC);\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$sql<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #D4D4D4\">*<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #CE9178\"> users <\/span><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #CE9178\"> id <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\"> ?&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$pdo<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">prepare<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$sql<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">execute<\/span><span style=\"color: #D4D4D4\">(&#91;<\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">&#93;);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$result<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">fetch<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">PDO<\/span><span style=\"color: #D4D4D4\">::FETCH_ASSOC);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>?<\/code>\u3067\u9806\u756a\u6307\u5b9a\u3059\u308b\u5f62\u5f0f\u3002<\/li>\n\n\n\n<li><code>execute()<\/code>\u306b\u914d\u5217\u3067\u5024\u3092\u6e21\u3059\u3002<\/li>\n\n\n\n<li>\u914d\u5217\u306e\u9806\u5e8f\u304c\u30af\u30a8\u30ea\u306e\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u9806\u306b\u5bfe\u5fdc\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u8907\u6570\u6761\u4ef6\u3067\u306e\u30d0\u30a4\u30f3\u30c9<\/h3>\n\n\n\n<p>\u540d\u524d\u4ed8\u304d\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3092\u8907\u6570\u4f7f\u3046\u30b1\u30fc\u30b9\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$sql = \"SELECT * FROM users WHERE age > :age AND status = :status\";\n$stmt = $pdo->prepare($sql);\n$stmt->execute(&#91;\n  ':age' => 20,\n  ':status' => 'active'\n&#93;);\n$results = $stmt->fetchAll(PDO::FETCH_ASSOC);\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$sql<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #D4D4D4\">*<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #CE9178\"> users <\/span><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #CE9178\"> age <\/span><span style=\"color: #D4D4D4\">&gt;<\/span><span style=\"color: #CE9178\"> :age <\/span><span style=\"color: #569CD6\">AND<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #569CD6\">status<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\"> :<\/span><span style=\"color: #569CD6\">status<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$pdo<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">prepare<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$sql<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">execute<\/span><span style=\"color: #D4D4D4\">(&#91;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #CE9178\">&#39;:age&#39;<\/span><span style=\"color: #D4D4D4\"> =&gt; <\/span><span style=\"color: #B5CEA8\">20<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #CE9178\">&#39;:status&#39;<\/span><span style=\"color: #D4D4D4\"> =&gt; <\/span><span style=\"color: #CE9178\">&#39;active&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">&#93;);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$results<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">fetchAll<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">PDO<\/span><span style=\"color: #D4D4D4\">::FETCH_ASSOC);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30d0\u30a4\u30f3\u30c9\u9806\u304c\u660e\u793a\u7684\u3067\u3001\u8907\u96d1\u306a\u6761\u4ef6\u5f0f\u306b\u9069\u3059\u308b\u3002<\/li>\n\n\n\n<li><code>fetchAll()<\/code>\u3067\u8907\u6570\u884c\u3092\u307e\u3068\u3081\u3066\u53d6\u5f97\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u540d\u524d\u4ed8\u304d vs \u756a\u53f7\u4ed8\u304d\u306e\u9055\u3044\u3068\u9078\u5b9a\u57fa\u6e96<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u540d\u524d\u4ed8\u304d<\/strong>\uff1a\u30af\u30a8\u30ea\u304c\u8aad\u307f\u3084\u3059\u304f\u3001\u5024\u306e\u610f\u5473\u304c\u660e\u793a\u3055\u308c\u308b\u3002\u6761\u4ef6\u304c\u591a\u3044\u5834\u5408\u3084\u9806\u5e8f\u304c\u8907\u96d1\u306a\u5834\u5408\u306b\u9069\u3057\u3066\u3044\u308b\u3002<\/li>\n\n\n\n<li><strong>\u756a\u53f7\u4ed8\u304d<\/strong>\uff1a\u7c21\u7d20\u306a\u30af\u30a8\u30ea\u306b\u9069\u3057\u3001\u914d\u5217\u3067\u307e\u3068\u3081\u3066\u6e21\u305b\u308b\u306e\u3067\u77ed\u304f\u66f8\u3051\u308b\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3069\u3061\u3089\u3082SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u5bfe\u7b56\u3068\u3057\u3066\u6709\u52b9\u3067\u3059\u304c\u3001\u5b9f\u52d9\u3067\u306f\u4fdd\u5b88\u6027\u306e\u89b3\u70b9\u304b\u3089<strong>\u540d\u524d\u4ed8\u304d\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u304c\u4e00\u822c\u7684<\/strong>\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u3088\u304f\u3042\u308b\u30df\u30b9\u30fb\u8aa4\u89e3\u30fb\u843d\u3068\u3057\u7a74<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306b\u30ab\u30e9\u30e0\u540d\u3084\u30c6\u30fc\u30d6\u30eb\u540d\u3092\u4f7f\u304a\u3046\u3068\u3059\u308b<\/h3>\n\n\n\n<p>\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306f<strong>\u5024\u306e\u307f<\/strong>\u306b\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u8aa4\u3063\u305f\u4f8b\u3067\u3059\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u30c6\u30fc\u30d6\u30eb\u540d\u306b\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3092\u4f7f\u3063\u3066\u3044\u308b\n$sql = \"SELECT * FROM :table WHERE id = :id\"; \/\/ \u52d5\u4f5c\u3057\u306a\u3044\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30c6\u30fc\u30d6\u30eb\u540d\u306b\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3092\u4f7f\u3063\u3066\u3044\u308b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$sql<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #D4D4D4\">*<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #CE9178\"> :<\/span><span style=\"color: #569CD6\">table<\/span><span style=\"color: #CE9178\"> <\/span><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #CE9178\"> id <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\"> :id&quot;<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u52d5\u4f5c\u3057\u306a\u3044<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306a\u69cb\u9020\u306b\u306f\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u3092\u4f7f\u3048\u306a\u3044\u305f\u3081\u3001\u4e8b\u524d\u306b\u59a5\u5f53\u6027\u30c1\u30a7\u30c3\u30af\u3092\u3057\u305f\u3046\u3048\u3067\u6587\u5b57\u5217\u9023\u7d50\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. bindValue\u3068bindParam\u306e\u9055\u3044\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>bindValue()<\/code>\uff1a\u305d\u306e\u6642\u70b9\u306e\u5024\u3092\u30d0\u30a4\u30f3\u30c9\uff08\u901a\u5e38\u306f\u3053\u3061\u3089\u3092\u4f7f\u7528\uff09<\/li>\n\n\n\n<li><code>bindParam()<\/code>\uff1a\u5909\u6570\u3078\u306e\u53c2\u7167\u3092\u30d0\u30a4\u30f3\u30c9\uff08\u5909\u6570\u306e\u5024\u304c\u5f8c\u3067\u5909\u308f\u308b\u5834\u5408\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u8aa4\u7528\u3059\u308b\u3068\u3001\u610f\u56f3\u3057\u306a\u3044\u5024\u304c\u9001\u4fe1\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. execute\u524d\u306eprepare\u5fd8\u308c<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u76f4\u63a5<code>execute()<\/code>\u306e\u307f\u3092\u547c\u3076\u3068\u3001<code>prepare<\/code>\u304c\u7701\u7565\u3055\u308c\u305f\u3068\u8aa4\u8a8d\u3055\u308c\u304c\u3061\u3067\u3059\u304c\u3001\u5fc5\u305a<code>prepare()<\/code>\u306f\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u672a\u5b9a\u7fa9\u306e$stmt\u3092\u5b9f\u884c\u3057\u3088\u3046\u3068\u3059\u308b\n$stmt->execute(&#91;':id' => 5&#93;);&lt;br><\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u672a\u5b9a\u7fa9\u306e$stmt\u3092\u5b9f\u884c\u3057\u3088\u3046\u3068\u3059\u308b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$stmt<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">execute<\/span><span style=\"color: #D4D4D4\">(&#91;<\/span><span style=\"color: #CE9178\">&#39;:id&#39;<\/span><span style=\"color: #D4D4D4\"> =&gt; <\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">&#93;);&lt;<\/span><span style=\"color: #569CD6\">br<\/span><span style=\"color: #D4D4D4\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u307e\u3068\u3081<\/h2>\n\n\n\n<p>PHP\u3067\u5b89\u5168\u306bSELECT\u3092\u5b9f\u884c\u3059\u308b\u306b\u306f\u3001<code>PDO<\/code>\u3068\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306e\u4f75\u7528\u304c\u57fa\u672c\u3067\u3059\u3002<br>\u540d\u524d\u4ed8\u304d\u3068\u756a\u53f7\u4ed8\u304d\u306e\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306b\u306f\u305d\u308c\u305e\u308c\u7279\u9577\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u53ef\u8aad\u6027\u3068\u4fdd\u5b88\u6027\u306e\u70b9\u304b\u3089\u306f\u540d\u524d\u4ed8\u304d\u306e\u5229\u7528\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u8aa4\u7528\u3057\u3084\u3059\u3044\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u306f\u3001\u69cb\u9020\u8981\u7d20\u306b\u5bfe\u3059\u308b\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306e\u8aa4\u9069\u7528\u3001<code>bindParam()<\/code>\u3068<code>bindValue()<\/code>\u306e\u6df7\u540c\u306a\u3069\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u7406\u89e3\u3057\u3001SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u5bfe\u7b56\u3068\u3057\u3066\u9069\u5207\u306a\u5b9f\u88c5\u3092\u5fc3\u304c\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8 2. PHP\u306e\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u306b\u3088\u308bSELECT\u3068\u306f\uff1f PHP\u3067SQL\u3092\u6271\u3046\u969b\u3001\u52d5\u7684\u306a\u5024\u3092\u76f4\u63a5\u30af\u30a8\u30ea\u6587\u5b57\u5217\u306b\u57cb\u3081\u8fbc\u3080\u3068\u3001SQL\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u306e\u30ea\u30b9\u30af\u304c\u751f\u3058\u307e\u3059\u3002\u3053\u308c\u3092\u56de\u907f\u3059\u308b\u4ee3\u8868\u7684\u306a\u624b\u6cd5\u304c\u300c\u30d7\u30ec\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":910,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[85],"tags":[],"class_list":["post-832","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=832"}],"version-history":[{"count":2,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/832\/revisions"}],"predecessor-version":[{"id":911,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/832\/revisions\/911"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/media\/910"}],"wp:attachment":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}