设置数据库,表的字符集都是utf8_general_ci
在dadabase.php里面设置
实例
<?php return[ 'type'=>'mysql', 'host'=>'127.0.0.1', 'dbname'=>'xxxxxxxxxxxx', 'username'=>'xxxxxxxxxx', 'password'=>'xxxxxxxxxxx', 'charset'=>'utf8' ];
运行实例 »
点击 "运行实例" 按钮查看在线实例
在connect.php里面设置
实例
<?php $db = require 'database.php'; $dsn = "{$db['type']}:host={$db['host']};dbname={$db['dbname']};charset={$db['charset']}"; $username = $db['username']; $password = $db['password']; try { $pdo = new PDO($dsn, $username, $password ); } catch (PDOException $e) { echo '数据库连接失败' . $e->getMessage(); }
运行实例 »
点击 "运行实例" 按钮查看在线实例