public function GetItemById($id) { $result = null; $conn = new Connection(); $cmd = $conn->stmt_init(); $query = ' SELECT id,author_id,content,meme_id FROM comments WHERE id = ? '; if ($cmd->prepare($query)) { $cmd->bind_param('i', $id); $cmd->execute(); $reader = $cmd->get_result(); if ($row = $reader->fetch_assoc()) { $result = $row; } $reader->close(); $cmd->close(); } $conn->close(); return $result; }
/** * Execute a Closure within a transaction. * * @param \Closure $callback * @return mixed * * @throws \Exception */ public function transaction(Closure $callback) { if ($this->getDriverName() == 'sqlsrv') { return parent::transaction($callback); } $this->pdo->exec('BEGIN TRAN'); try { $result = $callback($this); $this->pdo->exec('COMMIT TRAN'); } catch (\Exception $e) { $this->pdo->exec('ROLLBACK TRAN'); throw $e; } return $result; }
/** * Retrieve a user by the given credentials. * * @param array $credentials * @return \Auth\UserInterface|null */ public function retrieveByCredentials(array $credentials) { // First we will add each credential element to the query as a where clause. // Then we can execute the query and, if we found a user, return it in a // generic "user" object that will be utilized by the Guard instances. $query = $this->conn->table($this->table); foreach ($credentials as $key => $value) { if (!str_contains($key, 'password')) { $query->where($key, $value); } } // Now we are ready to execute the query to see if we have an user matching // the given credentials. If not, we will just return nulls and indicate // that there are no matching users for these given credential arrays. $user = $query->first(); if (!is_null($user)) { return new GenericUser((array) $user); } }
public function execute() { return $this->connection->execute($this); }
private function UpdateItem($item) { $result = null; $conn = new Connection(); $cmd = $conn->stmt_init(); $query = ' UPDATE users SET username = ?, password = ?, firstname = ?, lastname = ?, email = ? WHERE id = ? '; if ($cmd->prepare($query)) { $cmd->bind_param('sssssi', $item['username'], $item['password'], $item['firstname'], $item['lastname'], $item['email'], $item['id']); $cmd->execute(); $cmd->close(); } $conn->close(); }
private function createTable() { $this->connection->query("CREATE DATABASE IF NOT EXISTS test"); $this->connection->query("CREATE TABLE IF NOT EXISTS {$this->tableName} (`name` varchar(255),`value` integer(8)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); $this->connection->query("TRUNCATE TABLE {$this->tableName}"); }
/** * Create a raw database expression. * * @param mixed $value * @return \Database\Query\Expression */ public function raw($value) { return $this->connection->raw($value); }
public function AuthLike($meme_id, $author_id) { $result = false; $conn = new Connection(); $cmd = $conn->stmt_init(); $query = ' SELECT id FROM LIKES WHERE meme_id = ? AND author_id = ? '; if ($cmd->prepare($query)) { $cmd->bind_param('ii', $meme_id, $author_id); $cmd->execute(); $reader = $cmd->get_result(); if ($reader->fetch_array()) { $result = true; } $reader->close(); $cmd->close(); } $conn->close(); return $result; }
/** * Get a QueryBuilder instance for the given database Table. * * @param string $table * @return \Database\Query */ protected function table($table) { return $this->db->table($table); }
/** * Get a fresh query builder instance for the table. * * @return \Database\Query\Builder */ protected function getQuery() { return $this->connection->table($this->table); }
/** * Create a new database query * * @return \Database\Query */ public function newQuery() { return $this->connection->table($this->table); }
/** * Get a query builder for the cache table. * * @return \Database\Query\Builder */ protected function table() { return $this->connection->table($this->table); }
/** * Prepare the read write mode for database connection instance. * * @param \Database\Connection $connection * @param string $type * @return \Database\Connection */ protected function setPdoForType(Connection $connection, $type = null) { if ($type == 'read') { $connection->setPdo($connection->getReadPdo()); } else { if ($type == 'write') { $connection->setReadPdo($connection->getPdo()); } } return $connection; }