摘要:/* * 使用數(shù)據(jù)庫 * 第一步:連接數(shù)入庫 * 1、全局配置 \config\database.php 文件 * 2、動態(tài)配置(只適用一次使用) 方法在think\db\Query.php中有一個方法:connect() * public function conn2() * { * return Db::connect([ * 'ty
/*
* 使用數(shù)據(jù)庫
* 第一步:連接數(shù)入庫
* 1、全局配置 \config\database.php 文件
* 2、動態(tài)配置(只適用一次使用) 方法在think\db\Query.php中有一個方法:connect()
* public function conn2()
* {
* return Db::connect([
* 'type'=>'mysql',
* 'hostname'=>'localhost',
* 'database'=>'demo',
* 'username'=>'root',
* 'password'=>'root',
* ])
* -> table('student') -> where('id',2) -> value('name');
* }
*
*
* 3、DSN連接字符串
* 數(shù)據(jù)庫類型://用戶名:密碼@數(shù)據(jù)庫地址:端口號/數(shù)據(jù)庫的名稱#字符集
* public function conn3($dsn)
* {
* $dsn = 'mysql://root:root@localhost:3306/demo#utf8';
* return Db::table('student') -> where('id',5) -> value('name');
* }
*
*
* */
批改老師:查無此人批改時間:2019-06-14 14:19:07
老師總結(jié):完成的不錯。編程有很多設(shè)計(jì)模式,多了解,對以后工作幫助很大。繼續(xù)加油。