2 回答

TA貢獻2080條經驗 獲得超4個贊
您沒有聲明驅動程序,因此您得到'could not find driver'。此外,您還缺少命名 host= 參數。
要糾正此錯誤,請像這樣更改 PDO 實例化:
return new PDO(
'mysql:host='.$config['connection'].';dbname='.$config['name'],
$config['username'],
$config['password'],
$config['options']
);
您的$config數組沒有問題,并且也被正確包含。</span>

TA貢獻1815條經驗 獲得超10個贊
在 config.php 中,直接設置數組:
<?php
$config = [
'database' => [
'name' => 'schema_test',
'username' => 'name',
'password' => 'password',
'connection' => 'mysql:host=localhost:3306',
'options' => [],
]
];
在您的 bootstrap.php 中,請要求您的 config.php 文件如下:
require 'config.php';
并且不要忘記使用 $config['database']['name']...
- 2 回答
- 0 關注
- 183 瀏覽
添加回答
舉報