Beispiel #1
0
 public function getConnection()
 {
     if (!isset(SalamaSqlDatabase::$_connection[$this->_name])) {
         $backend = SalamaDatabaseManager::getCurrentBackend();
         $driver_name = sprintf("Salama%sDriver", ucfirst($backend['driver']));
         $driver = new $driver_name();
         $driver->dsn = $this->_dsn;
         $connection = $driver->connect();
         SalamaSqlDatabase::$_connection[$this->_name] = $connection;
     }
     return SalamaSqlDatabase::$_connection[$this->_name];
 }
 public function __construct()
 {
     $xml = simplexml_load_string(file_get_contents(Salama::$_settings['config'] . '/databases.xml'));
     $configuration = json_decode(json_encode($xml->xpath("//backend/configuration[not(@*)]")), true);
     self::$backend_global = $configuration[0];
     foreach (json_decode(json_encode($xml->xpath("//backend/configuration[(@*)]")), true) as $backend) {
         $backend_name = $backend['@attributes']['name'];
         unset($backend['@attributes']);
         self::$backends[$backend_name] = array_merge(self::$backend_global, $backend);
     }
     foreach (json_decode(json_encode($xml->xpath(sprintf("//configuration[@environment='%s']/database", Salama::$_settings['env']))), true) as $db) {
         $dsn = SalamaDatabaseManager::parse_dsn($db['dsn']);
         $database = sprintf("Salama%sDatabase", ucfirst($dsn['scheme']));
         $obj = new $database($db['@attributes']['name'], $dsn);
         self::$databases[$db['@attributes']['name']] = $obj;
     }
 }
Beispiel #3
0
 public function select($args, $query)
 {
     $backend = SalamaDatabaseManager::getCurrentBackend();
     $quote = $backend['quote'];
     if (empty($quote)) {
         $quote = '';
     }
     # setup select(), if no select() used and not a raw() query
     if (!$this->builder->recursive_array_search('raw', $query->methods)) {
         foreach ($query->_involved_tables as $k => $array) {
             $alias = $this->builder->getAlias($array['table'], $query);
             $select_fields = $this->_sel_fields(SalamaData::$c[$array['table']][SalamaBuild::$meta]['fields'], $alias, $quote);
         }
         $sql = implode(', ', $select_fields);
     } else {
         $select_key = $this->builder->recursive_array_search('select', $query->methods);
         $select_sql = isset($query->methods[$select_key][1][0]) ? $query->methods[$select_key][1][0] : null;
         $sql = $this->select($select_sql);
     }
     $this->sql = $sql;
 }