__construct() public method

\ManaPHP\Db\Adapter constructor
public __construct ( array $options )
$options array
Example #1
0
 /**
  * \ManaPHP\Db\Adapter constructor
  *
  * @param array|\ConfManaPHP\Db\Adapter\Mysql $options
  */
 public function __construct($options)
 {
     $this->_type = 'mysql';
     if (is_object($options)) {
         $options = (array) $options;
     }
     /** @noinspection AdditionOperationOnArraysInspection */
     $defaultOptions = ['host' => 'localhost', 'port' => 3306, 'username' => 'root', 'password' => '', 'options' => []];
     $options = array_merge($defaultOptions, $options);
     if (!isset($options['options'][\PDO::MYSQL_ATTR_INIT_COMMAND])) {
         $options['options'][\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'UTF8'";
     }
     parent::__construct($options);
 }
Example #2
0
 /**
  * Sqlite constructor.
  *
  * @param string|array $options
  *
  * @throws \ManaPHP\Db\Adapter\Sqlite\Exception
  */
 public function __construct($options)
 {
     $this->_type = 'sqlite';
     if (is_object($options)) {
         $options = (array) $options;
     } elseif (is_string($options)) {
         $options = ['file' => $options];
     }
     if (!isset($options['file'])) {
         throw new SqliteException('file is not provide to sqlite adapter.');
     }
     $options['dsn'] = $options['file'];
     unset($options['file']);
     parent::__construct($options);
 }