Esempio n. 1
0
 /**
  * Update an entity in the database.
  *
  * @param \Percy\Entity\EntityInterface $entity
  * @param array                         $scopes
  *
  * @return void
  */
 protected function updateEntity(EntityInterface $entity, array $scopes = [])
 {
     $update = $this->query->newUpdate();
     $update->table($entity->getDataSource());
     $update->cols($entity->getData($scopes, true));
     $update->where(sprintf('%s = ?', $entity->getPrimary()), $entity[$entity->getPrimary()]);
     $this->dbal->perform($update->getStatement(), $update->getBindValues());
 }
Esempio n. 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);
     }
 }
Esempio n. 3
0
<?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());
Esempio n. 4
0
     $errorExceptions = $e->getErrorExceptions();
     foreach ($errorExceptions as $errorException) {
         $flash->addMessage('error', $errorException->getMessage());
     }
     return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
 } catch (\Exception $e) {
     $flash->addMessage('error', $e->getMessage());
     return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
 }
 /*
  * Save results and redirect
  */
 try {
     $qf = new QueryFactory('mysql');
     /** @var SqlQuery\Mysql\Update $update */
     $update = $qf->newUpdate();
     $update->table('indiegogo')->where('Email = :email')->bindValue('email', $postParams['email']);
     if (!empty($postParams['shirtType'])) {
         $update->set('shirtType', ':shirtType')->bindValue('shirtType', $postParams['shirtType']);
     }
     if (!empty($postParams['shirtSize'])) {
         $update->set('shirtSize', ':shirtSize')->bindValue('shirtSize', $postParams['shirtSize']);
     }
     if (!empty($postParams['hoodieSize'])) {
         $update->set('hoodieSize', ':hoodieSize')->bindValue('hoodieSize', $postParams['hoodieSize']);
     }
     /** @var ExtendedPdo $pdo */
     $pdo = $this->get('pdo');
     $stm = $update->getStatement();
     $sth = $pdo->perform($stm, $update->getBindValues());
 } catch (\Exception $e) {