private function _conexion() { //$entorno = new Entorno(); //self::$config = $this->config_load($entorno->getEntorno().'app_config'); $configApp = new Config(); $this->config = $configApp->getBaseDatos(); if (empty($this->config['driver'])) { die('Por favor, establece un controlador de base de datos valido ' . $this->config['driver']); } $driver = strtoupper($this->config['driver']); switch ($driver) { case 'MYSQL': $this->_dbHost = $this->config['host']; $this->_dbbd = $this->config['nombre']; $this->_dbusuario = $this->config['usuario']; $this->_dbclave = $this->config['clave']; $this->pdo = new PDO('mysql:host=' . $this->_dbHost . '; dbname=' . $this->_dbbd, $this->_dbusuario, $this->_dbclave); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->pdo->exec("SET CHARACTER SET utf8"); $this->_cnx = $this->pdo; break; default: die('Base de datos no soporta: ' . $this->config['driver']); } }
<?php use App\Config; $configApp = new Config(); $entorno = $configApp->getBaseDatos(); $serviceContainer = \Propel\Runtime\Propel::getServiceContainer(); $serviceContainer->checkVersion('2.0.0-dev'); $serviceContainer->setAdapterClass('default', 'mysql'); $manager = new \Propel\Runtime\Connection\ConnectionManagerSingle(); $manager->setConfiguration(array('dsn' => 'mysql:host=' . $entorno['host'] . ';dbname=' . $entorno['nombre'] . ';port=' . $entorno['puerto'], 'user' => $entorno['usuario'], 'password' => $entorno['clave'], 'settings' => array('charset' => $entorno['charset'], 'queries' => array('utf8' => "SET NAMES utf8 COLLATE utf8_unicode_ci, COLLATION_CONNECTION = utf8_unicode_ci, COLLATION_DATABASE = utf8_unicode_ci, COLLATION_SERVER = utf8_unicode_ci")), 'classname' => '\\Propel\\Runtime\\Connection\\ConnectionWrapper')); $manager->setName('default'); $serviceContainer->setConnectionManager('default', $manager); $serviceContainer->setDefaultDatasource('default');