public static function getAll() { static::getConnection(); $prep = static::$con->prepare('SELECT * FROM ' . static::getTableName()); $prep->execute(); return $prep->fetchAll(); }
public function getTiposClientes() { $loConnection = new Connection(); $stmt = $loConnection->prepare('SELECT * FROM tiposClientes WHERE status <> 0'); $stmt->execute(); return $stmt->fetchAll(); }
public function delete($id) { $sql = "DELETE FROM {$this->table} WHERE id = :id"; $stmt = Connection::prepare($sql); $stmt->bindParam(':id', $id, PDO::PARAM_INT); return $stmt->execute(); }
public function findCatSubcat() { $sql = "SELECT categoria.id AS 'id_categoria', categoria.nome AS 'categoria', \nsubcategoria.id AS 'id_subcategoria', subcategoria.nome AS 'subcategoria'\nFROM tbl_subcategorias subcategoria INNER JOIN tbl_categorias categoria\nON subcategoria.id_categoria = categoria.id ORDER BY categoria.nome"; $stmt = Connection::prepare($sql); $stmt->execute(); return $stmt->fetchAll(); }
public function setCliente(array $laCliente) { $loConnection = new Connection(); $stmt = $loConnection->prepare('INSERT INTO clientes(nome,cpf,tipoCliente,ativo,status) VALUES ("' . $laCliente['nome'] . '","' . $laCliente['cpf'] . '","' . $laCliente['tipoCliente'] . '",1,1)'); $stmt->execute(); header('location:index.php'); }
/** * @return KVDdom_LazyDomainObjectCollection */ protected function abstractFindAll() { $sql = $this->getFindAllStatement(); $this->_sessie->getSqlLogger()->log($sql); $stmt = $this->_conn->prepare($sql); return $this->executeFindMany($stmt); }
public function deleteById($id) { $this->id = $id; $dbh = new Connection(); $sql = 'DELETE FROM ' . static::TABLE . ' WHERE id=' . $id; $sth = $dbh->prepare($sql); $sth->execute(); }
public function update($id) { $sql = "UPDATE {$this->table} SET nome = :nome WHERE id = :id"; $stmt = Connection::prepare($sql); $stmt->bindParam(':nome', $this->nome); $stmt->bindParam(':id', $id); return $stmt->execute(); }
public function update($title, $id) { $this->id = $id; $this->title = $title; $dbh = new Connection(); $sql = "UPDATE new_news SET title='{$title}' WHERE id='{$id}'"; $sth = $dbh->prepare($sql); $sth->execute(); }
function install_all($install) { $connection = Connection::prepare(new Config(new PostgresType(), host, port, user, pass)); $connection->connect(); $connection->begin(); install_packages($connection, $install); $connection->commit(); $connection->close(); }
public function update($files, $cook) { $this->files = $files; $this->cook = $cook; $dbh = new Connection(); $sql = "UPDATE info SET img='{$files}' WHERE login='******'"; $sth = $dbh->prepare($sql); $sth->execute(); }
public function insert($text, $avtor, $id_news) { $this->text = $text; $this->avtor = $avtor; $this->id_news = $id_news; $dbh = new Connection(); $sql = "INSERT INTO coments (text, avtor, id_news, date)VALUE ('" . $text . "','" . $avtor . "','" . $id_news . "',NOW())"; $sth = $dbh->prepare($sql); $sth->execute(); }
public function insert($name, $text, $avtor, $img_src = '') { $this->name = $name; $this->text = $text; $this->avtor = $avtor; $this->img_src = $img_src; $dbh = new Connection(); $sql = "INSERT INTO golos (title, text, avtor, img, date) VALUES ('" . $name . "','" . $text . "','" . $avtor . "','" . $img_src . "',NOW())"; $sth = $dbh->prepare($sql); $sth->execute(); }
public function update(Connection $connection) { $sth = $connection->prepare($this->statement); $field = explode('_', $this->table)[2]; $seeder = explode('_', $this->table)[1] . 'r_' . explode('_', $this->table)[0]; $getTotalCount = $connection->prepare('SELECT count(*) FROM prod'); $getTotalCount->execute(); $times = (int) $getTotalCount->fetch(PDO::FETCH_ASSOC)['count']; $getFirstId = $connection->prepare('SELECT id FROM prod ORDER BY id LIMIT 1'); $getFirstId->execute(); $firstId = (int) $getFirstId->fetch(PDO::FETCH_ASSOC)['id']; if (method_exists($this, $seeder)) { $generator = $this->{$seeder}($times, $sth, $firstId); foreach ($generator as $stmt) { $result = $stmt->execute(); } } else { throw new Exception('No rules to seed ' . $this->table . ' table'); } return $result; }
/** * {@inheritdoc} */ public function scheduleForChannelAndLocale(ChannelInterface $channel, LocaleInterface $locale) { $sql = <<<SQL DELETE c FROM pim_catalog_completeness c WHERE c.channel_id = :channel_id AND c.locale_id = :locale_id SQL; $sql = $this->applyTableNames($sql); $stmt = $this->connection->prepare($sql); $stmt->bindValue('channel_id', $channel->getId()); $stmt->bindValue('locale_id', $locale->getId()); $stmt->execute(); }
/** * @param Model $model * @return bool * @throws Exception */ public function delete(Model $model) { if (!isset($this->key)) { throw new Exception('Delete not implemented for this store.'); } if (!$model instanceof $this->model) { throw new Exception(get_class($model) . ' is an invalid model type for this store.'); } $data = $model->toArray(); $stmt = $this->connection->prepare("DELETE FROM `{$this->table}` WHERE `{$this->key}` = :k;"); $stmt->bindValue(':k', $data[$this->key]); $stmt->execute(); $this->cacheSet($data[$this->key], null); return true; }
private function sql() { $sql = 'SELECT * FROM ' . $this->table; if ($this->where) { $sql .= ' WHERE ' . $this->where; } if ($this->order) { $sql .= ' ORDER BY ' . $this->order; } if ($this->start !== $this->end) { $sql .= ' LIMIT ' . $this->start . ', ' . $this->end; } $statement = Connection::prepare($sql); $statement->execute($this->parameters); return $statement; }
public function update() { $db = new Connection(); $table = strtolower(get_class($this)); $prefixe = substr($table, 0, 3) . "_"; $props = get_object_vars($this); unset($props["id"]); foreach ($props as $prop => $value) { $up[] = $prefixe . $prop . "=:" . $prop; $prop = ":" . $prop; } $query = "UPDATE " . $table . " SET " . implode(',', $up); $query .= " WHERE " . $prefixe . "id=" . $this->getId(); $request = $db->prepare($query); $request->execute($props); $db = null; }
public function createUser($userName, $password, $email) { try { $hashedPassword = password_hash($password, PASSWORD_DEFAULT); $LastLogin = date('Y-m-d H:i:s'); $db = new Connection(); $stmt = $db->prepare("INSERT INTO\n users (id,Username,Password, LastLogin,Email, Created)\n VALUES (:id, :UserName,:Password, :LastLogin, :Email, :Created)"); $stmt->bindParam(':id', $id); $stmt->bindParam(':UserName', $userName); $stmt->bindParam(':Password', $hashedPassword); $stmt->bindParam(':LastLogin', $LastLogin); $stmt->bindParam(':Email', $email); $stmt->bindParam(':Created', $Created); $stmt->execute(); } catch (PDOException $e) { throw new PDOException($e); } }
/** * @param int|null $limit * @return Model\Collection */ public function get($limit = null) { if (!is_null($limit)) { $this->limit($limit); } $sql = $this->getSql(); self::$queries[] = ['sql' => $sql, 'bind' => $this->bind]; $stmt = $this->connection->prepare($sql); $collectionType = $this->model . 'Collection'; /** @var \Block8\Database\Model\Collection $rtn */ $rtn = new $collectionType(); if ($stmt->execute($this->bind)) { $rows = $stmt->fetchAll(Connection::FETCH_ASSOC); $modelType = $this->model; foreach ($rows as $key => $item) { $rtn->add($key, new $modelType($item)); } } return $rtn; }
/** * Writes session data. * * @param string A session ID * @param string A serialized chunk of session data * * @return boolean true, if the session was written, otherwise an exception is thrown * * @throws <b>DatabaseException</b> If the session data cannot be written */ public function sessionWrite($id, $data) { // get table/column $db_table = $this->getParameterHolder()->get('db_table'); $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); $db_id_col = $this->getParameterHolder()->get('db_id_col', 'sess_id'); $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); $sql = 'UPDATE ' . $db_table . ' SET ' . $db_data_col . ' = ?, ' . $db_time_col . ' = ' . time() . ' WHERE ' . $db_id_col . '= ?'; try { $stmt = $this->db->prepare($sql); $stmt->bindParam(1, $data, PDO::PARAM_STR); // setString(1, $data); $stmt->bindParam(2, $id, PDO::PARAM_STR); // setString(2, $id); $stmt->execute(); return true; } catch (PDOException $e) { $error = sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage()); throw new sfDatabaseException($error); } return false; }
public function getMessages($tope, $idUsuario) { $db = new Connection(); $limite = $tope; $query = "SELECT MENSAJE.contenido, USUARIO.nombre, USUARIO.apellido, MURO.privacidad,MENSAJE.fecha_alta\n\t\t\t\t\tFROM MENSAJE\n\t\t\t\t\tINNER JOIN MURO ON MENSAJE.id_muro = MURO.id_muro\n\t\t\t\t\tINNER JOIN USUARIO ON USUARIO.id_usuario = MENSAJE.id_usuario\n\t\t\t\t\tWHERE MURO.id_usuario = ?\n\t\t\t\t\tORDER BY fecha_alta DESC LIMIT ? "; $stmt = $db->prepare($query); $stmt->bind_param("ii", $idUsuario, $limite); $stmt->execute(); $stmt->bind_result($contenido, $nombre, $apellido, $privacidad, $fecha_alta); $rows = 0; $row = array(); $result = $stmt->get_result(); $obj = new stdClass(); while ($obj = $result->fetch_object()) { $rows++; $row[] = $obj; } if ($rows > 0) { return $row; } else { return null; } }
public function update($id) { $sql = "UPDATE {$this->table} SET id_categoria = :id_categoria, id_subcategoria = :id_subcategoria, nome = :nome, modelo = :modelo, descricao = :descricao, ean = :ean, status_produto = :status_produto, comprimento = :comprimento, largura = :largura, altura = :altura, peso = :peso, quantidade = :quantidade, valor_unitario = :valor_unitario, url_foto_capa = :url_foto_capa, destaque = :destaque, lancamento = :lancamento, meta_tag_titulo = :meta_tag_titulo, meta_tag_descricao = :meta_tag_descricao, meta_tag_palavra_chave = :meta_tag_palavra_chave, tag_produto = :tag_produto, data_cadastro = :data_cadastro WHERE id = :id"; $stmt = Connection::prepare($sql); $stmt->bindParam(':id_categoria', $this->id_categoria); $stmt->bindParam(':id_subcategoria', $this->id_subcategoria); $stmt->bindParam(':nome', $this->nome); $stmt->bindParam(':modelo', $this->modelo); $stmt->bindParam(':descricao', $this->descricao); $stmt->bindParam(':ean', $this->ean); $stmt->bindParam(':status_produto', $this->status_produto); $stmt->bindParam(':comprimento', $this->comprimento); $stmt->bindParam(':largura', $this->largura); $stmt->bindParam(':altura', $this->altura); $stmt->bindParam(':peso', $this->peso); $stmt->bindParam(':quantidade', $this->quantidade); $stmt->bindParam(':valor_unitario', $this->valor_unitario); $stmt->bindParam(':url_foto_capa', $this->url_foto_capa); $stmt->bindParam(':destaque', $this->destaque); $stmt->bindParam(':lancamento', $this->lancamento); $stmt->bindParam(':meta_tag_titulo', $this->meta_tag_titulo); $stmt->bindParam(':meta_tag_descricao', $this->meta_tag_descricao); $stmt->bindParam(':meta_tag_palavra_chave', $this->meta_tag_palavra_chave); $stmt->bindParam(':tag_produto', $this->tag_produto); $stmt->bindParam(':data_cadastro', $this->data_cadastro); $stmt->bindParam(':id', $id); return $stmt->execute(); }
public function delete() { $sql = 'DELETE FROM ' . static::table() . ' WHERE id = ?'; $statement = Connection::prepare($sql); $statement->execute(array($this->id)); }
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Cuervo</title> </head> <body> <?php require_once './cuervo/cuervo.php'; require_once './cuervo/datab/PostgresType.php'; require_once Connection_php; package('pack1'); viewing('ViewPack1'); Connection::prepare(new Config(new PostgresType(), host, port, user, pass)); $view = new ViewPack1(); $view->save_perro(array('nombre' => 'rocky', 'id' => 22, 'persona_id' => 5)); function Aj() { class AA { } return new AA(); } echo get_class(Aj()); ?> </body> </html>
/** * Save instance config (to files and database) * * @param array $config * @param Connection $connection */ public function saveInstanceConfig($config, $connection) { // Set site title $sql = "UPDATE SystemPreferences SET value = ? WHERE varname = 'SiteTitle'"; $stmt = $connection->prepare($sql); $stmt->bindValue(1, $config['site_title']); $stmt->execute(); $sql = "UPDATE SystemPreferences SET value = ? WHERE varname = 'EmailFromAddress' OR varname = 'EmailContact'"; $stmt = $connection->prepare($sql); $stmt->bindValue(1, $config['user_email']); $stmt->execute(); // Set admin user $user = new User(); $salt = $user->generateRandomString(); $password = implode(User::HASH_SEP, array(User::HASH_ALGO, $salt, hash(User::HASH_ALGO, $salt . $config['recheck_user_password']))); $sql = "UPDATE liveuser_users SET Password = ?, EMail = ?, time_updated = NOW(), time_created = NOW(), status = '1', is_admin = '1' WHERE id = 1"; $stmt = $connection->prepare($sql); $stmt->bindValue(1, $password); $stmt->bindValue(2, $config['user_email']); $stmt->execute(); $sql = "UPDATE SystemPreferences SET value = ? WHERE varname = 'SiteSecretKey'"; $stmt = $connection->prepare($sql); $stmt->bindValue(1, sha1($config['site_title'] . mt_rand())); $stmt->execute(); $sql = "INSERT INTO SystemPreferences (`varname`, `value`, `last_modified`) VALUES ('installation_id', ?, NOW())"; $stmt = $connection->prepare($sql); $stmt->bindValue(1, sha1($config['site_title'] . mt_rand())); $stmt->execute(); $result = $this->setupHtaccess(); if (!empty($result)) { throw new IOException(implode(" ", $result) . " Most likely it's caused by wrong permissions."); } }
$stmt->bindValue(3, $sala); $stmt->bindValue(4, $sabor); $stmt->bindValue(5, $cod); $stmt->bindValue(6, $date); $stmt->execute(); } catch (PDOException $e) { } echo $cod; } else { if ($action == 'relogin') { $user = $_POST['reuser']; $pass = $_POST['repass']; $id = 0; try { $query = "SELECT * FROM readmin WHERE retname = ? AND retpass = ? "; $stmt = Connection::prepare($query); $stmt->bindValue(1, $user); $stmt->bindValue(2, $pass); $stmt->execute(); $res = $stmt; foreach ($res as $key => $val) { $id = $val->id; } if ($id != 0) { session_start(); $_SESSION['id'] = $id; $_SESSION['name'] = $user; $_SESSION['pass'] = $pass; } } catch (PDOException $e) { echo $e;
/** * Apply only the current migration. * @return true on success or false on failure */ function apply(Connection $db) { $q = $db->prepare("CREATE TABLE migrations (\n id int not null auto_increment primary key,\n name varchar(255) not null,\n created_at timestamp not null default current_timestamp,\n\n INDEX(name)\n );"); return $q->execute(); }
public function findUsuario($login, $senha) { $sql = "SELECT * FROM {$this->table} WHERE login = :login AND senha = :senha"; $stmt = Connection::prepare($sql); $stmt->bindParam(':login', $login, PDO::PARAM_STR); $stmt->bindParam(':senha', $senha, PDO::PARAM_STR); $stmt->execute(); return $stmt->fetch(); }
public function __construct($sql, $params, Connection $connection, Database $db) { try { $stmt = $connection->prepare($sql); $stmt->execute($params); $this->statement = $stmt; $this->connection = $connection; } catch (\PDOException $e) { // 服务端断开时重连一次 if ($e->errorInfo[1] == 2006 || $e->errorInfo[1] == 2013) { $master_or_slave = $connection->getMasterOrSlave(); $db->closeConnection($master_or_slave, $connection->getConnectionIndex()); $connection = $db->getConnection($master_or_slave == Connection::MASTER_CONNECTION); try { $stmt = $connection->prepare($sql); $stmt->execute($params); $this->statement = $stmt; $this->connection = $connection; } catch (\PDOException $ex) { $db->rollback(); throw $ex; } } else { $db->rollback(); throw $e; } } }