/** * Инициализация объекта для работы с БД. * * @return Db_Pdo */ protected function get_db() { $config = $this->_config['db']; $db = Db_Pdo::create($config['dsn'], $config['user'], $config['passwd'], $config['options']); $db->exec('SET NAMES utf8'); return $db; }
public function __construct($file_name, $dsn, $user, $passwd) { if (false === ($this->_link = dbase_open($file_name, 0))) { throw new Exception('Не удалось открыть файл ' . $file_name); } $options = array(Db_Pdo::ATTR_ERRMODE => Db_Pdo::ERRMODE_EXCEPTION); $this->_db = Db_Pdo::create($dsn, $user, $passwd, $options); $this->_db->exec('SET NAMES utf8'); $sql = ' INSERT INTO regions (code, name) VALUES (:code, :name) '; $this->_insert_region = $this->_db->prepare($sql); $sql = ' INSERT INTO localities (region_id, code, name, type) VALUES (:region_id, :code, :name, :type) '; $this->_insert_locality = $this->_db->prepare($sql); }