コード例 #1
0
 /**
  * Returns a new INSERT object.
  * @param string $tableName
  * @return Common\InsertInterface
  */
 public function newInsert($tableName = null)
 {
     $insert = parent::newInsert();
     if (null !== $tableName) {
         $insert->into($tableName);
     }
     return $insert;
 }
コード例 #2
0
 /**
  * Saves a set of data to the table
  * This function will either insert or update, depending on if the entity passed already has an identifier set. The
  * generated/passed ID will be returned.
  *
  * @param object|array $data Data to save
  * @param string $table Table to save to
  * @param string $identifierColumn Identifier column to work against
  * @return int|string
  */
 public function save($data, $table, $identifierColumn = 'id')
 {
     $data = $this->convertToArray($data);
     if (!empty($data[$identifierColumn])) {
         $update = $this->queryHandler->newUpdate();
         $update->table($table)->cols(array_keys($data))->where($identifierColumn . ' = :' . $identifierColumn)->bindValues($data);
         $this->db->perform($update->__toString(), $update->getBindValues());
         return $data[$identifierColumn];
     } else {
         $insert = $this->queryHandler->newInsert();
         $insert->into($table)->cols(array_keys($data))->bindValues($data);
         $this->db->perform($insert->__toString(), $insert->getBindValues());
         $name = $insert->getLastInsertIdName($identifierColumn);
         return $this->db->lastInsertId($name);
     }
 }
コード例 #3
0
ファイル: SqlStore.php プロジェクト: acredula/percy
 /**
  * Persist relationships to data store.
  *
  * @param \Percy\Entity\EntityInterface $entity
  * @param array                         $rels
  * @param array                         $map
  *
  * @return void
  */
 public function relationships(EntityInterface $entity, array $rels, array $map)
 {
     $this->dbal->beginTransaction();
     foreach ($rels as $rel) {
         $exists = $this->dbal->fetchOne(sprintf("select * from %s where %s = '%s' and %s = '%s'", $map['defined_in']['table'], $map['defined_in']['primary'], $entity[$map['defined_in']['entity']], $map['target']['relationship'], $rel));
         if ($exists !== false) {
             continue;
         }
         $data = [$map['defined_in']['primary'] => $entity[$map['defined_in']['entity']], $map['target']['relationship'] => $rel];
         $insert = $this->query->newInsert();
         $insert->into($map['defined_in']['table']);
         $insert->cols($data);
         $this->dbal->perform($insert->getStatement(), $insert->getBindValues());
     }
     $this->dbal->commit();
 }
コード例 #4
0
ファイル: db.php プロジェクト: djmattyg007/pictorials
 /**
  * @return Aura\SqlQuery\Common\InsertInterface
  */
 public static function newInsert()
 {
     return self::$queryFactory->newInsert();
 }
コード例 #5
0
ファイル: aurasql.php プロジェクト: Zetaphor/brokecommerce
<?php

require 'config.php';
use Aura\SqlQuery\QueryFactory;
use Aura\Sql\ExtendedPdo;
$query_factory = new QueryFactory('mysql');
$insert = $query_factory->newInsert();
$update = $query_factory->newUpdate();
$delete = $query_factory->newDelete();
$pdo = new ExtendedPdo('mysql:host=' . $mysql_host . ';dbname=' . $mysql_db, $mysql_user, $mysql_pass, array(), array());
function pdoSelect($select)
{
    global $pdo;
    $sth = $pdo->prepare($select->getStatement());
    $sth->execute($select->getBindValues());
    return $sth->fetchAll(PDO::FETCH_ASSOC);
}
function pdoInsert($table, $data)
{
    global $pdo, $insert;
    $insert->into($table)->cols(array_keys($data))->bindValues($data);
    $sth = $pdo->prepare($insert->getStatement());
    $sth->execute($insert->getBindValues());
    return $pdo->lastInsertId();
}
function pdoUpdate($table, $id, $data)
{
    global $pdo, $update;
    $update->table($table)->where('id = ?', $id)->cols(array_keys($data))->bindValues($data);
    $sth = $pdo->prepare($update->getStatement());
    return $sth->execute($update->getBindValues());
コード例 #6
0
ファイル: Builder.php プロジェクト: formula9/framework
 public function insert(string $table, $bindings)
 {
     $insert = $this->query_factory->newInsert();
     $insert->into($table)->cols($bindings);
     return $insert;
 }
コード例 #7
0
ファイル: Query.php プロジェクト: chajr/RPiAS_server
 /**
  * return insert object
  *
  * @return \Aura\SqlQuery\Common\InsertInterface
  */
 public function insert()
 {
     return $this->_factory->newInsert();
 }