Beispiel #1
0
 /**
  * Set the field to count.
  * @param $fields
  * @return $this
  * @throws FatalException
  */
 public function fields($fields)
 {
     if (!is_string($fields)) {
         throw new FatalException('Only strings are allowed in COUNT query');
     }
     $this->fields = sprintf('COUNT(%s)', DatabaseConnectionFactory::get()->quote($fields));
     return $this;
 }
Beispiel #2
0
 /**
  * When databases are present in the configuration file, they get
  * initialized in this function.
  */
 public function setDatabases()
 {
     $databases = $this->get('Database');
     if (!empty($databases)) {
         foreach ($databases as $id => $config) {
             DatabaseConnectionFactory::create($id, $config);
         }
     }
 }
 /**
  * Write a record to the database.
  * @param array $record
  */
 protected function write(array $record)
 {
     $currentDatabase = DatabaseConnectionFactory::getActiveDatabaseId();
     try {
         DatabaseConnectionFactory::select(static::DATABASE);
         $values = ['message' => $record['message'], 'context' => print_r($record['context'], true), 'level' => $record['level_name']];
         static::$table->insert()->values($values)->execute();
     } catch (\Exception $e) {
         // Fail silently, as logging a logging error results in an infinite loop
     } finally {
         DatabaseConnectionFactory::select($currentDatabase);
     }
 }
Beispiel #4
0
 /**
  * Execute the query.
  *
  * @return DatabaseRecord
  * @throws FatalException
  */
 public function execute()
 {
     if ($this->table === null) {
         throw new FatalException(sprintf('No table defined for method `%s`.', $this->getQueryType()));
     }
     if ($this->queryType === static::MODE_QUERY) {
         return DatabaseConnectionFactory::get()->query($this);
     } else {
         return DatabaseConnectionFactory::get()->execute($this);
     }
 }
Beispiel #5
0
<?php

function autoloader($class)
{
    $include = __DIR__ . '/../Soneritics/' . $class . '.php';
    require_once $include;
}
spl_autoload_register('autoloader');
\Database\DatabaseConnectionFactory::create('sandbox', ['type' => 'PDOMySQL', 'dsn' => 'mysql:dbname=sandbox;host=localhost', 'user' => 'sandbox', 'password' => 'sandbox']);
$tables = Database\Database::getTables();
foreach ($tables as $table) {
    print_r($table);
    print_r($table->getColumns());
}
Beispiel #6
0
 /**
  * Override the default execute function.
  *
  * @return int Last insert ID.
  */
 public function execute()
 {
     $result = parent::execute();
     return DatabaseConnectionFactory::get()->lastInsertId();
 }