支付宝赞助帐号:service@kuitao8.com 

Yii2.0 数据库连结

Created2015-04-07   Views 3461    Author 懒人程序
db.php
01 <?php
02 return [
03     'class' => 'yii\db\Connection',
04     'dsn' => 'mysql:host=localhost;dbname=reportsa_macromoney'// MySQL, MariaDB
05     //'dsn' => 'sqlite:/path/to/database/file', // SQLite
06     //'dsn' => 'pgsql:host=localhost;port=5432;dbname=mydatabase', // PostgreSQL
07     //'dsn' => 'cubrid:dbname=demodb;host=localhost;port=33000', // CUBRID
08     //'dsn' => 'sqlsrv:Server=localhost;Database=mydatabase', // MS SQL Server, sqlsrv driver
09     //'dsn' => 'dblib:host=localhost;dbname=mydatabase', // MS SQL Server, dblib driver
10     //'dsn' => 'mssql:host=localhost;dbname=mydatabase', // MS SQL Server, mssql driver
11     //'dsn' => 'oci:dbname=//localhost:1521/mydatabase', // Oracle
12     'username' => 'root',
13     'password' => '$123',
14     'charset' => 'utf8',
15     ];
16 ?>      

在config/main.php里配置

1 'components' => [   
2         'db'=>require(__DIR__ . '/db.php'),
3         .................
4     ]

连结的方法

1 $connection = \Yii::$app->db;
2 $secondaryConnection = \Yii::$app->secondDb;

上一篇: PHP 判断时间,日期 格式是否正确代码
下一篇: yii2 jui的简单用法
支持键盘 ← →

邮件订阅

订阅我们的精彩内容