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

相关文章:

  • 2021-12-04
  • 2021-05-06
  • 2021-11-27
  • 2021-12-15
  • 2021-12-16
  • 2022-02-17
  • 2022-03-06
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2021-07-20
  • 2022-01-03
  • 2021-08-17
  • 2021-06-10
  • 2022-12-23
相关资源
相似解决方案