for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\component\database\connector;
use nebula\component\database\exception\ConfigException;
/**
* 连接器
*/
class MySQLConnector extends Connector
{
protected static $type = 'mysql';
protected $defaultConfig = [
'database-prefix' => '',
'database-name' => 'nebula',
'database-user' => 'root',
'database-password' => '',
'server-host' => '127.0.0.1',
'server-port' => 3306,
'database-charset' => 'utf8mb4',
];
* 应用配置
*
* @param array $config
* @return void
public function applyConfig(array $config)
foreach ($config as $name => $value) {
if (in_array($name, array_keys($defaultConfig))) {
$defaultConfig
$this->config[$name] = $config[$name] ?? $this->defaultConfig[$name];
} else {
throw new ConfigException(sprintf(__CLASS__.' : unknown config property %s', $name));
}
* 获取PDO链接描述
* @return string
public function getDsn():string
return 'mysql:host='.$this->config['server-host'].';charset='.$this->config['database-charset'].';port='.$this->config['server-port'];