-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
数据库支持 new Database('mysql://root:[email protected]/test'); 这样的快速调用写法
- Loading branch information
1 parent
088888b
commit 6cb390f
Showing
5 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,8 @@ class MyQEE_Database extends Database_QueryBuilder | |
/** | ||
* 返回数据库实例化对象 | ||
* | ||
* 支持 Database::instance('mysqli://root:[email protected]/myqee/'); 的方式 | ||
* | ||
* @param string $config_name | ||
* @return Database | ||
*/ | ||
|
@@ -110,7 +112,9 @@ public static function instance($config_name = 'default') | |
} | ||
|
||
/** | ||
* Sets the initial columns to select from. | ||
* new Database('default'); | ||
* 支持 | ||
* new Database('mysqli://root:[email protected]/myqee/'); 的方式 | ||
* | ||
* @param array column list | ||
* @return void | ||
|
@@ -121,10 +125,25 @@ public function __construct($config_name = 'default') | |
{ | ||
$this->config = $config_name; | ||
} | ||
elseif (false!==strpos($config_name,'://')) | ||
{ | ||
list($type) = explode('://', $config_name); | ||
|
||
$this->config = array | ||
( | ||
'type' => $type, | ||
'connection' => $config_name, | ||
'table_prefix' => '', | ||
'charset' => 'utf8', | ||
'caching' => false, | ||
'profiling' => true, | ||
); | ||
} | ||
else | ||
{ | ||
$this->config = Core::config('database.' . $config_name); | ||
} | ||
|
||
$this->config['charset'] = strtoupper($this->config['charset']); | ||
if ( !isset($this->config['auto_change_charset']) ) | ||
{ | ||
|
@@ -567,7 +586,7 @@ public static function parse_dsn($dsn) | |
if ( isset($connection['path']) && $connection['path'] ) | ||
{ | ||
// Strip leading slash | ||
$db['database'] = substr($connection['path'], 1); | ||
$db['database'] = trim(trim(substr($connection['path'], 1),'/')); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters