Example #1
0
File: SQL.php Project: mpf-soft/mpf
 public static function importFromFile($filePath)
 {
     try {
         self::$connection->query(file_get_contents($filePath))->fetch();
     } catch (\Exception $e) {
     }
 }
Example #2
0
 /**
  * Deletes rows that match condition. It will return number of affected rows.
  * @return int
  */
 public function delete()
 {
     $query = "DELETE FROM `{$this->table}` {$this->join}";
     if ($this->condition) {
         $query .= " WHERE {$this->condition}";
     }
     if ($this->limit) {
         $query .= " LIMIT {$this->limit}";
     }
     return $this->connection->execQuery($query, $this->params);
 }
Example #3
0
 /**
  * Reload info from DB for current object. Will also call afterLoad method in case updates are needed.
  */
 public function reload()
 {
     $this->_relations = array();
     if (is_array($this->_pk)) {
         $c = $p = [];
         foreach ($this->_originalPk as $k => $v) {
             $c[] = "`{$k}` = :pk_{$k}";
             $p[":pk_{$k}"] = $v;
         }
         $this->_attributes = $this->_db->table($this->_tableName)->where(implode(" AND ", $c), $p)->first();
     } else {
         $this->_attributes = $this->_db->table($this->_tableName)->where("`{$this->_pk}` = :__pk")->setParam(':__pk', $this->_originalPk)->first();
     }
     $this->_updatedAttributes = [];
     $this->afterLoad();
 }
Example #4
0
 protected function _columnsForRelation(DbRelation $relation, PDOConnection $connection, $relationName)
 {
     $sqlColumns = $connection->getTableColumns($relation->getTableName());
     $columnAlias = str_replace('.', '_', str_replace('_', '__', $relationName));
     $columns = [];
     foreach ($sqlColumns as $column) {
         $columns[] = "`{$relation->getTableAlias()}`.`{$column['Field']}` as ___{$columnAlias}___{$column['Field']}";
     }
     return $columns;
 }
Example #5
0
File: App.php Project: mpf-soft/mpf
 /**
  * Shortcut to Sql database connection;
  * @param string[] $options Optional; Some config options can be set and it will return a specific instance with that config applied.
  * @return \mpf\datasources\sql\PDOConnection
  */
 public function sql($options = [])
 {
     return PDOConnection::get($options);
 }