Yii2 mysql连接配置调试
1 basic/config/db.php添加
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=172.16.8.12;dbname=student',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
// Schema cache options (for production environment)
//'enableSchemaCache' => true,
//'schemaCacheDuration' => 60,
//'schemaCache' => 'cache',
];
2 basic/test/index test controller添加
$connection = Yii::$app->db;
$sql = "select * from student limit 1";
$student = $connection->createCommand($sql)->queryAll();
var_dump($student);
3 访问测试
http://{url}/test/index

浙公网安备 33010602011771号