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(); }
/** * 字段自增 * * $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); }
public static function getPetByApproved($petApprove) { //$cleanPetName = \Core\Db::escape($petName); $sql = "SELECT * FROM pet WHERE `approved`='{$petApprove}';"; $res = \Core\Db::execute($sql); return $res; }
/** * 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}';"); }
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; }
/** * 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); }
public static function getImagesByPetId($petId) { return \Core\Db::execute("SELECT * FROM image WHERE `pet_id`='{$petId}';"); }