{"id":840,"date":"2025-08-05T16:27:28","date_gmt":"2025-08-05T07:27:28","guid":{"rendered":"https:\/\/nexive.tech\/?p=840"},"modified":"2025-08-05T16:27:28","modified_gmt":"2025-08-05T07:27: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-db%e6%8e%a5%e7%b6%9a%e6%83%85%e5%a0%b1%e3%81%ae%e5%a4%96%e9%83%a8%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e5%8c%96%e3%81%a8","status":"publish","type":"post","link":"https:\/\/nexive.tech\/?p=840","title":{"rendered":"\u3010\u30b5\u30af\u30c3\u3068\u89e3\u8aac\u3011PHP DB\u63a5\u7d9a\u60c5\u5831\u306e\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u5316\u3068\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56"},"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>DB\u63a5\u7d9a\u60c5\u5831\u3092PHP\u30b3\u30fc\u30c9\u304b\u3089\u5206\u96e2\u3057\u3001\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u7ba1\u7406\u3059\u308b\u65b9\u6cd5\u3092\u89e3\u8aac<\/li>\n\n\n\n<li>\u60c5\u5831\u6f0f\u6d29\u3092\u9632\u3050\u305f\u3081\u306e\u57fa\u672c\u7684\u306a\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56\u3092\u7d39\u4ecb<\/li>\n\n\n\n<li>\u5b9f\u52d9\u3067\u63a8\u5968\u3055\u308c\u308b\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3\u3068\u6ce8\u610f\u70b9\u3092\u542b\u3080<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. PHP\u306b\u304a\u3051\u308bDB\u63a5\u7d9a\u60c5\u5831\u306e\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u5316\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>PHP\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3059\u308b\u969b\u3001\u591a\u304f\u306e\u521d\u5b66\u8005\u304c\u63a5\u7d9a\u60c5\u5831\uff08\u30db\u30b9\u30c8\u540d\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u306a\u3069\uff09\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u5185\u306b\u76f4\u63a5\u8a18\u8ff0\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u3053\u308c\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u306e\u30ea\u30b9\u30af\u3068\u306a\u308b\u305f\u3081\u3001\u5b9f\u52d9\u3067\u306f<strong>\u63a5\u7d9a\u60c5\u5831\u3092\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u306b\u5206\u96e2<\/strong>\u3059\u308b\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u305f\u3068\u3048\u3070\u3001<code>config.php<\/code> \u3084 <code>.env<\/code> \u30d5\u30a1\u30a4\u30eb\u306a\u3069\u306b\u63a5\u7d9a\u60c5\u5831\u3092\u5b9a\u7fa9\u3057\u3001\u305d\u308c\u3092 <code>require<\/code> \u3084\u74b0\u5883\u5909\u6570\u7d4c\u7531\u3067\u8aad\u307f\u8fbc\u3080\u65b9\u5f0f\u304c\u63a1\u7528\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30ed\u30b8\u30c3\u30af\u3068\u6a5f\u5bc6\u60c5\u5831\u3092\u660e\u78ba\u306b\u5206\u96e2\u3067\u304d\u3001\u4fdd\u5b88\u6027\u3084\u518d\u5229\u7528\u6027\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u7279\u306b\u8907\u6570\u74b0\u5883\uff08\u958b\u767a\u30fb\u672c\u756a\u306a\u3069\uff09\u3067\u8a2d\u5b9a\u3092\u5207\u308a\u66ff\u3048\u308b\u5834\u9762\u3067\u306f\u3001\u3053\u306e\u624b\u6cd5\u304c\u975e\u5e38\u306b\u6709\u52b9\u3067\u3059\u3002\u3055\u3089\u306b\u3001\u6a5f\u5bc6\u60c5\u5831\u3092Git\u306a\u3069\u306eVCS\u304b\u3089\u9664\u5916\u3057\u3084\u3059\u304f\u306a\u308b\u3068\u3044\u3046\u5229\u70b9\u3082\u3042\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\u7684\u306a\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u5316\u306e\u4f8b<\/h3>\n\n\n\n<p>\u3082\u3063\u3068\u3082\u57fa\u672c\u7684\u306a\u624b\u6cd5\u306f\u3001PHP\u30d5\u30a1\u30a4\u30eb\u3092\u7528\u3044\u305f\u8a2d\u5b9a\u7ba1\u7406\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>\/\/ config.php\nreturn &#91;\n  'host' => 'localhost',\n  'dbname' => 'sampledb',\n  'user' => 'dbuser',\n  'pass' => 'secret123'\n&#93;;\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\">\/\/ config.php<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> &#91;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #CE9178\">&#39;host&#39;<\/span><span style=\"color: #D4D4D4\"> =&gt; <\/span><span style=\"color: #CE9178\">&#39;localhost&#39;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #CE9178\">&#39;dbname&#39;<\/span><span style=\"color: #D4D4D4\"> =&gt; <\/span><span style=\"color: #CE9178\">&#39;sampledb&#39;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #CE9178\">&#39;user&#39;<\/span><span style=\"color: #D4D4D4\"> =&gt; <\/span><span style=\"color: #CE9178\">&#39;dbuser&#39;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #CE9178\">&#39;pass&#39;<\/span><span style=\"color: #D4D4D4\"> =&gt; <\/span><span style=\"color: #CE9178\">&#39;secret123&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">&#93;;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\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>\/\/ main.php\n$config = require 'config.php';\n\n\/\/ PDO\u3092\u7528\u3044\u305fDB\u63a5\u7d9a\n$dsn = \"mysql:host={$config&#91;'host'&#93;};dbname={$config&#91;'dbname'&#93;};charset=utf8mb4\";\n$pdo = new PDO($dsn, $config&#91;'user'&#93;, $config&#91;'pass'&#93;);\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\">\/\/ main.php<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$config<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #C586C0\">require<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;config.php&#39;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ PDO\u3092\u7528\u3044\u305fDB\u63a5\u7d9a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$dsn<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;mysql:host={<\/span><span style=\"color: #9CDCFE\">$config<\/span><span style=\"color: #CE9178\">&#91;&#39;host&#39;&#93;};dbname={<\/span><span style=\"color: #9CDCFE\">$config<\/span><span style=\"color: #CE9178\">&#91;&#39;dbname&#39;&#93;};charset=utf8mb4&quot;<\/span><span style=\"color: #D4D4D4\">;<\/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: #9CDCFE\">$dsn<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$config<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #CE9178\">&#39;user&#39;<\/span><span style=\"color: #D4D4D4\">&#93;, <\/span><span style=\"color: #9CDCFE\">$config<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #CE9178\">&#39;pass&#39;<\/span><span style=\"color: #D4D4D4\">&#93;);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092 <code>return<\/code> \u5f62\u5f0f\u3067\u66f8\u304f\u3053\u3068\u3067\u3001\u914d\u5217\u3068\u3057\u3066\u7c21\u5358\u306b\u8aad\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">.env\u30d5\u30a1\u30a4\u30eb\u3068dotenv\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u6d3b\u7528\uff08Laravel\u7b49\uff09<\/h3>\n\n\n\n<p>\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u306f <code>.env<\/code> \u30d5\u30a1\u30a4\u30eb\u3068\u74b0\u5883\u5909\u6570\u304c\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002\u4ee5\u4e0b\u306f <code>vlucas\/phpdotenv<\/code> \u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u65b9\u6cd5\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># .env\nDB_HOST=localhost\nDB_NAME=sampledb\nDB_USER=dbuser\nDB_PASS=secret123\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\"># .env<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">DB_HOST=localhost<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">DB_NAME=sampledb<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">DB_USER=dbuser<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">DB_PASS=secret123<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\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>\/\/ bootstrap.php\nrequire 'vendor\/autoload.php';\n\n$dotenv = Dotenv\\Dotenv::createImmutable(__DIR__);\n$dotenv->load();\n\n$dsn = \"mysql:host={$_ENV&#91;'DB_HOST'&#93;};dbname={$_ENV&#91;'DB_NAME'&#93;};charset=utf8mb4\";\n$pdo = new PDO($dsn, $_ENV&#91;'DB_USER'&#93;, $_ENV&#91;'DB_PASS'&#93;);\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\">\/\/ bootstrap.php<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">require<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;vendor\/autoload.php&#39;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$dotenv<\/span><span style=\"color: #D4D4D4\"> = Dotenv\\<\/span><span style=\"color: #4EC9B0\">Dotenv<\/span><span style=\"color: #D4D4D4\">::<\/span><span style=\"color: #DCDCAA\">createImmutable<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">__DIR__<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$dotenv<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">load<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$dsn<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;mysql:host={<\/span><span style=\"color: #9CDCFE\">$_ENV<\/span><span style=\"color: #CE9178\">&#91;&#39;DB_HOST&#39;&#93;};dbname={<\/span><span style=\"color: #9CDCFE\">$_ENV<\/span><span style=\"color: #CE9178\">&#91;&#39;DB_NAME&#39;&#93;};charset=utf8mb4&quot;<\/span><span style=\"color: #D4D4D4\">;<\/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: #9CDCFE\">$dsn<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$_ENV<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #CE9178\">&#39;DB_USER&#39;<\/span><span style=\"color: #D4D4D4\">&#93;, <\/span><span style=\"color: #9CDCFE\">$_ENV<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #CE9178\">&#39;DB_PASS&#39;<\/span><span style=\"color: #D4D4D4\">&#93;);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u624b\u6cd5\u3067\u306f<code>.env<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406\u304b\u3089\u9664\u5916\u3057\u3001\u5225\u9014 <code>.env.example<\/code> \u3092\u914d\u5e03\u3059\u308b\u5f62\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u9762\u306e\u88dc\u8db3\u3068\u30a2\u30af\u30bb\u30b9\u5236\u9650<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.env<\/code> \u3084 <code>config.php<\/code> \u306f\u3001Web\u30b5\u30fc\u30d0\u30fc\u306e\u516c\u958b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e<strong>\u5916<\/strong>\u306b\u914d\u7f6e\u3059\u308b\u3053\u3068\u304c\u57fa\u672c\u3067\u3059\u3002<\/li>\n\n\n\n<li>\u8aa4\u3063\u3066\u516c\u958b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u914d\u7f6e\u3059\u308b\u5834\u5408\u306f <code>.htaccess<\/code> \u7b49\u3067\u30a2\u30af\u30bb\u30b9\u7981\u6b62\u8a2d\u5b9a\u3092\u5fc5\u305a\u884c\u3044\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406 <code>.gitignore<\/code> \u306b <code>config.php<\/code> \u3084 <code>.env<\/code> \u3092\u8a18\u8ff0\u3057\u3066\u9664\u5916\u3057\u3001\u6f0f\u6d29\u30ea\u30b9\u30af\u3092\u4e0b\u3052\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u307e\u305f\u3001\u53ef\u80fd\u3067\u3042\u308c\u3070\u74b0\u5883\u5909\u6570\u306fOS\u30ec\u30d9\u30eb\u3067\u8a2d\u5b9a\u3057\u3001PHP\u30b3\u30fc\u30c9\u3067\u306f <code>getenv()<\/code> \u3092\u901a\u3058\u3066\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\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<ul class=\"wp-block-list\">\n<li><strong>config.php\u3092\u76f4\u4e0b\u306e<code>public\/<\/code>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u7f6e\u304f<\/strong>\uff1aURL\u304b\u3089\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u53ef\u80fd\u3068\u306a\u308a\u3001\u91cd\u5927\u306a\u60c5\u5831\u6f0f\u6d29\u306b\u3064\u306a\u304c\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong><code>.env<\/code>\u3092Git\u306b\u30b3\u30df\u30c3\u30c8\u3057\u3066\u3057\u307e\u3046<\/strong>\uff1a\u521d\u671f\u69cb\u7bc9\u6642\u306e\u3046\u3063\u304b\u308a\u30df\u30b9\u3068\u3057\u3066\u975e\u5e38\u306b\u591a\u3044\u4e8b\u4f8b\u3067\u3059\u3002\u5fc5\u305a <code>.gitignore<\/code> \u306b\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\u3002<\/li>\n\n\n\n<li><strong><code>require<\/code>\u6642\u306e\u30d1\u30b9\u30df\u30b9<\/strong>\uff1a\u7d76\u5bfe\u30d1\u30b9\u304b <code>__DIR__<\/code> \u5b9a\u6570\u3092\u7528\u3044\u3066\u3001\u5b9f\u884c\u6642\u306b\u610f\u56f3\u3057\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u304c\u8aad\u307f\u8fbc\u307e\u308c\u306a\u3044\u3088\u3046\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/li>\n\n\n\n<li><strong>PHP\u30a8\u30e9\u30fc\u51fa\u529b\u3092\u672c\u756a\u74b0\u5883\u3067\u6709\u52b9\u306e\u307e\u307e\u306b\u3059\u308b<\/strong>\uff1aDB\u63a5\u7d9a\u30a8\u30e9\u30fc\u6642\u306b\u63a5\u7d9a\u60c5\u5831\u304c\u305d\u306e\u307e\u307e\u9732\u51fa\u3059\u308b\u30b1\u30fc\u30b9\u304c\u3042\u308a\u307e\u3059\u3002\u9069\u5207\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u30ed\u30b0\u51fa\u529b\u306e\u5206\u96e2\u304c\u5fc5\u9808\u3067\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u307e\u3068\u3081<\/h2>\n\n\n\n<p>PHP\u3067DB\u63a5\u7d9a\u60c5\u5831\u3092\u6271\u3046\u969b\u306f\u3001\u5fc5\u305a\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u5316\u3092\u884c\u3044\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30ed\u30b8\u30c3\u30af\u304b\u3089\u5206\u96e2\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306f\u516c\u958b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5916\u306b\u914d\u7f6e\u3057\u3001VCS\u9664\u5916\u3001\u30a2\u30af\u30bb\u30b9\u5236\u5fa1\u3001\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u3044\u3063\u305f\u57fa\u672c\u5bfe\u7b56\u3092\u8b1b\u3058\u308b\u3053\u3068\u3067\u3001\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30ea\u30b9\u30af\u3092\u5927\u5e45\u306b\u4f4e\u6e1b\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5b9f\u52d9\u3067\u306f<code>.env<\/code>\u65b9\u5f0f\u3084\u914d\u5217\u5f62\u5f0f\u306e<code>config.php<\/code>\u306a\u3069\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u898f\u6a21\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u6709\u7121\u306b\u5fdc\u3058\u3066\u6700\u9069\u306a\u65b9\u6cd5\u3092\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8 2. PHP\u306b\u304a\u3051\u308bDB\u63a5\u7d9a\u60c5\u5831\u306e\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u5316\u3068\u306f\uff1f PHP\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3059\u308b\u969b\u3001\u591a\u304f\u306e\u521d\u5b66\u8005\u304c\u63a5\u7d9a\u60c5\u5831\uff08\u30db\u30b9\u30c8\u540d\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u306a\u3069\uff09\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u5185\u306b\u76f4\u63a5\u8a18\u8ff0\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u3053\u308c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":918,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[85],"tags":[],"class_list":["post-840","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\/840","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=840"}],"version-history":[{"count":2,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/840\/revisions"}],"predecessor-version":[{"id":919,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/840\/revisions\/919"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/media\/918"}],"wp:attachment":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}