Get default port for named adapter
public static getDefaultPortForAdapter ( string $adapterName ) : integer | ||
$adapterName | string | |
Результат | integer |
/** * Creates database object based on form data. * * @throws Exception|Zend_Db_Adapter_Exception * @return array The database connection info. Can be passed into Piwik::createDatabaseObject. */ public function createDatabaseObject() { $dbname = $this->getSubmitValue('dbname'); if (empty($dbname)) { throw new Exception("No database name"); } $adapter = $this->getSubmitValue('adapter'); $port = Adapter::getDefaultPortForAdapter($adapter); # NOTE: Using the first schema by default. This will have to be # changed if we intend to support different engines of Mysql # or any other database (if any). $dbInfos = array('host' => $this->getSubmitValue('host'), 'username' => $this->getSubmitValue('username'), 'password' => $this->getSubmitValue('password'), 'dbname' => $dbname, 'tables_prefix' => $this->getSubmitValue('tables_prefix'), 'adapter' => $adapter, 'port' => $port, 'schema' => Config::getInstance()->database['schema'], 'type' => $this->getSubmitValue('type')); if (($portIndex = strpos($dbInfos['host'], '/')) !== false) { // unix_socket=/path/sock.n $dbInfos['port'] = substr($dbInfos['host'], $portIndex); $dbInfos['host'] = ''; } else { if (($portIndex = strpos($dbInfos['host'], ':')) !== false) { // host:port $dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1); $dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex); } } try { @Db::createDatabaseObject($dbInfos); } catch (Zend_Db_Adapter_Exception $e) { $db = Adapter::factory($adapter, $dbInfos, $connect = false); // database not found, we try to create it if ($db->isErrNo($e, '1049')) { $dbInfosConnectOnly = $dbInfos; $dbInfosConnectOnly['dbname'] = null; @Db::createDatabaseObject($dbInfosConnectOnly); @DbHelper::createDatabase($dbInfos['dbname']); // select the newly created database @Db::createDatabaseObject($dbInfos); } else { throw $e; } } return $dbInfos; }
/** * Creates database object based on form data. * * @throws Exception|Zend_Db_Adapter_Exception * @return array The database connection info. Can be passed into Piwik::createDatabaseObject. */ public function createDatabaseObject() { $dbname = $this->getSubmitValue('dbname'); if (empty($dbname)) { throw new Exception("No database name"); } $adapter = $this->getSubmitValue('adapter'); $port = Adapter::getDefaultPortForAdapter($adapter); $dbInfos = array('host' => $this->getSubmitValue('host'), 'username' => $this->getSubmitValue('username'), 'password' => $this->getSubmitValue('password'), 'dbname' => $dbname, 'tables_prefix' => $this->getSubmitValue('tables_prefix'), 'adapter' => $adapter, 'port' => $port); if (($portIndex = strpos($dbInfos['host'], '/')) !== false) { // unix_socket=/path/sock.n $dbInfos['port'] = substr($dbInfos['host'], $portIndex); $dbInfos['host'] = ''; } else { if (($portIndex = strpos($dbInfos['host'], ':')) !== false) { // host:port $dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1); $dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex); } } try { @Db::createDatabaseObject($dbInfos); } catch (Zend_Db_Adapter_Exception $e) { $db = Adapter::factory($adapter, $dbInfos, $connect = false); // database not found, we try to create it if ($db->isErrNo($e, '1049')) { $dbInfosConnectOnly = $dbInfos; $dbInfosConnectOnly['dbname'] = null; @Db::createDatabaseObject($dbInfosConnectOnly); @DbHelper::createDatabase($dbInfos['dbname']); // select the newly created database @Db::createDatabaseObject($dbInfos); } else { throw $e; } } return $dbInfos; }