[2002] PDOException in Connection.php line 293
$this->fetchType = $config['result_type'];
}
try {
if (empty($config['dsn'])) {
$config['dsn'] = $this->parseDsn($config);
}
if ($config['debug']) {
$startTime = microtime(true);
}
$this->li
if ($config['debug']) {
// 记录数据库连接信息
Log::record('[ DB ] CONNECT:[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $config['dsn'], 'sql');
}
} catch (\PDOException $e) {
if ($autoConnection) {
Log::record($e->getMessage(), 'error');
return $this->connect($autoConnection, $li
} else {
Call Stack
in Connection.php line 293
at PDO->__construct('mysql:host=127.0.0.1...', 'root', '123456', [0, 2, 0, ...]) in Connection.php line 293
at Connection->connect() in Connection.php line 989
at Connection->initConnect(false) in Connection.php line 346
at Connection->query('SHOW COLUMNS FROM `t...', [], false, true) in Mysql.php line 65
at Mysql->getFields('tp_admin') in Query.php line 1757
at Query->getTableInfo('tp_admin', 'type') in Query.php line 1805
at Query->getFieldsType('tp_admin') in Query.php line 1811
at Query->getFieldsBind('tp_admin') in Builder.php line 93
at Builder->parseData(['username' => '测试管理员1', 'password' => '123456'], ['table' => 'tp_admin', 'where' => [], 'field' => '*', ...]) in Builder.php line 724
at Builder->insert(['username' => '测试管理员1', 'password' => '123456'], ['table' => 'tp_admin', 'where' => [], 'field' => '*', ...], false) in Query.php line 2094
at Query->insert(['username' => '测试管理员1', 'password' => '123456']) in Admin.php line 18
at Admin->add()
at ReflectionMethod->invokeArgs(ob
at App::invokeMethod([ob
at App::module(['admin', 'admin', 'add'], ['app_host' => '', 'app_debug' => true, 'app_trace' => false, ...], null) in App.php line 457
at App::exec(['type' => 'module', 'module' => ['admin', 'admin', 'add']], ['app_host' => '', 'app_debug' => true, 'app_trace' => false, ...]) in App.php line 139
at App::run() in start.php line 19
at require('D:\wamp64\www\tp5\th...') in index.php line 18
下面的是我的代码和数据库的设置
public function add(){
if (request()->isPost()) {
$data=[
'username'=>input('username'),
'password'=>input('password')
];
if (Db::name('admin')->insert($data)) {
return $this->success('添加管理员成功!','alist');
}else{
return $this->error('添加管理员失败!');
}
return;
}
return view();
}
数据库设置
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'databa
// 用户名
'username' => 'root',
// 密码
'password' => '123456',
// 端口
'hostport' => '',
// 连接dsn
'dsn' => '',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'tp_',
// 数据库调试模式
'debug' => true,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 数据集返回类型
'resultset_type' => 'array',
// 自动写入时间戳字段
'auto_timestamp' => false,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析
'sql_explain' => false,
最佳答案