PHP学院的中学生
- PHP学院的中学生 回答了问题 请问一下如何统计网站的 UV 呢?
点击后的数据是直接存入数据库吗?
- PHP学院的中学生 回复了 LaravelCode 的回答
新增一个 db 连接
'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=test', 'username' => '***', 'password' => '**', 'charset' => 'utf8', ], 'db2' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=test2', 'username' => '***', 'password' => '***', 'charset' => 'utf8', ], ],
然后在模型中指定连接 实现
getDb()
方法/** * {@inheritdoc} */ public static function tableName() { return 'post'; } /** * @return \yii\db\Connection the database connection used by this AR class. */ public static function getDb() { return Yii::$app->get('db2'); }
还可以使用 gii 生成模型 指定下
Database Connection ID
为db2
就好至于用法和以前的 AR 类没有区别。
@LaravelCode 哦哦,好的
是阿里云OSS吗?
- PHP学院的中学生 回复了 LaravelCode 的回答
新增一个 db 连接
'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=test', 'username' => '***', 'password' => '**', 'charset' => 'utf8', ], 'db2' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=test2', 'username' => '***', 'password' => '***', 'charset' => 'utf8', ], ],
然后在模型中指定连接 实现
getDb()
方法/** * {@inheritdoc} */ public static function tableName() { return 'post'; } /** * @return \yii\db\Connection the database connection used by this AR class. */ public static function getDb() { return Yii::$app->get('db2'); }
还可以使用 gii 生成模型 指定下
Database Connection ID
为db2
就好至于用法和以前的 AR 类没有区别。
public static function tableName()
{return 'test2';
}
这个tablename不应该是数据表的名字么,你怎么写的是数据库的名字呢?
- PHP学院的中学生 2019-03-19 已签到连续签到2天,获得了10个金钱
- PHP学院的中学生 发表了说说2019年3月19日签到
esharts 你值得拥有:https://echarts.baidu.com/examples/#chart-type-pie
这个兼容性怎么样呢?