Esempio n. 1
0
    public static function createAdoption($adoptionObj)
    {
        $user_id_adopter = \Core\Db::escape($adoptionObj->getUserIdAdopter());
        $user_id_poster = \Core\Db::escape($adoptionObj->getUserIdPoster());
        $pet_id = \Core\Db::escape($adoptionObj->getPetId());
        $created = $adoptionObj->getCreated();
        $updated = $adoptionObj->getUpdated();
        $visibility = $adoptionObj->getVisibility();
        $sql = <<<q
INSERT INTO `adoption`(
`id`,
`user_id_adopter`, 
`user_id_poster`,
`pet_id`,
`created`,
`updated`,
`visibility`) 
VALUES (
DEFAULT,
'{$user_id_adopter}',
'{$user_id_poster}',
'{$pet_id}',
{$created},
{$updated},
'{$visibility}');
q;
        $res = \Core\Db::execute($sql);
        return $res === false ? false : \Core\Db::insertId();
    }
Esempio n. 2
0
 /**
  * 字段自增
  *
  * $this->increment(['a'=>1, 'b'=>-2], ['id'=>1])
  *
  * @param array $data 字段和值
  * @param array $filter 条件
  * @return int 影响行数
  */
 public function increment(array $data, array $filter)
 {
     $table = $this->db->table($this->tableName);
     $sql = "UPDATE {$table} SET ";
     foreach ($data as $key => $val) {
         $sql .= " `{$key}` = `{$key}` + " . intval($val) . ",";
     }
     $where = $this->parseFilter($filter);
     $sql = rtrim($sql, ',');
     if ($where) {
         $sql .= " WHERE {$where}";
     }
     return $this->db->execute($sql);
 }
Esempio n. 3
0
 public static function getPetByApproved($petApprove)
 {
     //$cleanPetName = \Core\Db::escape($petName);
     $sql = "SELECT * FROM pet WHERE `approved`='{$petApprove}';";
     $res = \Core\Db::execute($sql);
     return $res;
 }
Esempio n. 4
0
 /**
  * Select a row from the user table by username
  * @param type $userName   email to select on
  * @return type  mixed      false on failure, array of results otherwise - see http://php.net/manual/en/mysqli.query.php
  * @throws Exception     
  */
 public static function getUserByUsername($userName)
 {
     $userName = \Core\Db::escape($userName);
     return \Core\Db::execute("SELECT * FROM `user` WHERE `username`='{$userName}';");
 }
Esempio n. 5
0
 public static function getNextThread()
 {
     $sql = "SELECT MAX(thread_id) FROM message;";
     $res = \Core\Db::execute($sql);
     return isset($res[0]['MAX(thread_id)']) ? $res[0]['MAX(thread_id)'] + 1 : null;
 }
Esempio n. 6
0
 /**
  * Remove a pet from a user's PetBasket
  * @param mixed $userId
  * @param mixed $petId
  * @return type
  */
 public static function remove($userId, $petId)
 {
     $userId = \Core\Db::escape($userId);
     $petId = \Core\Db::escape($petId);
     $sql = "DELETE FROM `basket` WHERE `user_id`='user:{$userId}' AND `pet_id`='pet:{$petId}';";
     return \Core\Db::execute($sql);
 }
Esempio n. 7
0
 public static function getImagesByPetId($petId)
 {
     return \Core\Db::execute("SELECT * FROM image WHERE `pet_id`='{$petId}';");
 }