📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)
ページの作成:「== 概要 == <br><br> == INIファイルの読み込み == ==== 使用例 ==== <syntaxhighlight lang="ini"> [development] host = "localhost" dbname = "dev_database" username = "dev_user" password = "dev_password" charset = "utf8mb4" [production] host = "production.example.com" dbname = "prod_database" username = "prod_user" password = "prod_password" charset = "utf8mb4" [testing] host = "test.example.com" dbname = "test_database" username = "t…」 |
|||
| 6行目: | 6行目: | ||
==== 使用例 ==== | ==== 使用例 ==== | ||
<syntaxhighlight lang="ini"> | <syntaxhighlight lang="ini"> | ||
# セクション無し | |||
host = "localhost" | |||
dbname = "your_database_name" | |||
username = "your_username" | |||
password = "your_password" | |||
charset = "utf8mb4" | |||
</syntaxhighlight> | |||
<br> | |||
<syntaxhighlight lang="ini"> | |||
# セクションあり | |||
[development] | [development] | ||
host = "localhost" | host = "localhost" | ||
dbname = "dev_database" | dbname = "dev_database" | ||
username = "dev_user" | username = "dev_user" | ||
password = "dev_password" | password = "dev_password" | ||
charset = "utf8mb4" | charset = "utf8mb4" | ||
[production] | [production] | ||
host = "production.example.com" | host = "production.example.com" | ||
dbname = "prod_database" | dbname = "prod_database" | ||
username = "prod_user" | username = "prod_user" | ||
password = "prod_password" | password = "prod_password" | ||
charset = "utf8mb4" | charset = "utf8mb4" | ||
[testing] | [testing] | ||
host = "test.example.com" | host = "test.example.com" | ||
dbname = "test_database" | dbname = "test_database" | ||
username = "test_user" | username = "test_user" | ||
password = "test_password" | password = "test_password" | ||
charset = "utf8mb4" | charset = "utf8mb4" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
| 31行目: | 41行目: | ||
<?php | <?php | ||
try { | try { | ||
// | // parse_ini_file関数を使用してINIファイルを読み込む (セクション無し) | ||
$config = parse_ini_file('hoge.ini'); | $config = parse_ini_file('hoge.ini'); | ||
// | // parse_ini_file関数を使用してINIファイルを読み込む (セクションあり) | ||
$config = parse_ini_file($iniPath, true); | $config = parse_ini_file($iniPath, true); | ||
| 68行目: | 77行目: | ||
// 接続オプションを設定 | // 接続オプションを設定 | ||
// エラーモード : 例外をスロー | |||
// フェッチモード : 連想配列として結果を取得 | |||
// プリペアドステートメントのエミュレーションを無効化 | |||
$options = [ | $options = [ | ||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | ||