/** @return DatabaseReader|string|array|void */ public static function query($query, $args = null, $flags = 0) { if (!self::$default && self::$connectHandler) { self::$connectHandler[0]->{self::$connectHandler[1]}(); } return self::$default->query($query, $args, $flags); }
/** * @param string $userUid * * @return int Number of destroyed sessions. */ public function destroySessions($userUid) { // Run two separate queries so we know exactly how many sessions are deleted. $destroyed = $this->connection->query('DELETE s FROM {sessions} s INNER JOIN {oxygen_session} os ON os.sid = s.sid WHERE os.uid = :uid', array('uid' => $userUid), array('return' => Database::RETURN_AFFECTED)); $this->connection->query('DELETE FROM {oxygen_session} WHERE uid = :uid', array('uid' => $userUid)); return $destroyed; }
protected function cleanup() { // Test could have been skipped if (null !== $this->dbConnection) { foreach (array('apb_queue', 'apb_msg', 'apb_msg_chan', 'apb_sub', 'apb_chan') as $table) { $this->dbConnection->query("DELETE FROM {" . $table . "}"); } } }
public function testLastID() { require __DIR__ . '/config/database_test.php'; $db = new DatabaseConnection($host, $database, $user, $password); $insert_result = $db->query("INSERT INTO characters (id, name, description, type, dead, stage, hp) \r\n\t\t\tVALUES ('9999', 'Carla', 'The swordmaster of Melee Island', 'pirate', 'false', '4', '87');"); $actual = $db->lastID(); $expected = '9999'; $delete_result = $db->query("DELETE FROM characters WHERE id = '9999'"); $this->assertNotEmpty($actual, 'Function LastID returning empty value. Check TestDatabaseConnection::lastID()'); $this->assertEquals($expected, $actual, 'Function LastID not returning expected value. Check TestDatabaseConnection::lastID()'); }
/** * {@inheritdoc} */ public function useNonce($nonce, $expiresAt) { if ($expiresAt < time()) { throw new Oxygen_Exception(Oxygen_Exception::NONCE_EXPIRED); } $cleanNonce = strtr($nonce, ['-' => '']); $nonceUsed = (bool) $this->connection->query('SELECT 1 FROM {oxygen_nonce} WHERE nonce = :nonce', [':nonce' => $cleanNonce])->fetchField(); if ($nonceUsed) { throw new Oxygen_Exception(Oxygen_Exception::NONCE_ALREADY_USED); } $this->connection->query('INSERT INTO {oxygen_nonce} (nonce, expires) VALUES (:nonce, :expires)', [':nonce' => $cleanNonce, ':expires' => $expiresAt]); }
function __construct(DatabaseConnection $parent) { //echo "Opening Connection\n"; if ($parent->is_transaction()) { $this->using_savepoints = true; $this->savepoint_name = 'transaction_' . uniqid(); $parent->query('SAVEPOINT ' . pg_escape_identifier($this->savepoint_name)); } else { $this->using_savepoints = false; $parent->query("START TRANSACTION"); } $this->parent_connection = $parent; }
public function refreshUserList() { //assim evitamos a necessidade de consultar o banco a cada requisição de lista $dbconn = new DatabaseConnection('localhost', 'user', 'password'); $results = $dbconn->query('select name from user'); $this->setUserList(sort($results)); }
/** * Delete the character with that ID * * @throws StatusCodeException 404 if was not deleted * * @param DatabaseConnection database class instance * @param mixed ID number, could be a string or an int */ public static function delete(DatabaseConnection $db, $id) { $success = $db->query('DELETE FROM characters WHERE id = ?;', [$id]); if (!$success) { throw new StatusCodeException(404); } }
public function getUserList() { $dbconn = new DatabaseConnection('localhost', 'user', 'password'); $results = $dbconn->query('select name from user'); sort($results); return $results; }
public function getListaUsuario($dbconn = null) { if (!isset($dbconn) || !$dbconn instanceof DatabaseConnection) { $dbconn = new DatabaseConnection('localhost', 'root', ''); } $results = $dbconn->query('SELECT name FROM users'); sort($results); return $results; }
public function submitComment() { $conn = new DatabaseConnection(); if (!isset($_GET['replyid'])) { $sentence = 'CALL addComment(' . $_SESSION['bookid'] . ',' . $_SESSION['id'] . ",'" . $_POST['comment'] . "')"; } else { $sentence = 'CALL addReply(' . $_SESSION['bookid'] . ',' . $_SESSION['id'] . ',' . $conn->quote($_POST['reply']) . ',' . $_GET['replyid'] . ')'; } $conn->query($sentence); }
public function getUserList() { $server = "localhost"; $user = "******"; $password = "******"; $dbconn = new DatabaseConnection($server, $user, $password); if ($dbconn->connect_error) { die("Conexão falhou: " . $dbconn->connection_error); } else { $results = $dbconn->query('select name from user'); sort($results); return $results; } }
/** * @return array */ private function getExtensions() { // Select all columns; 'filename' is the primary key. $query = "SELECT filename, name, type, owner, status, bootstrap, info FROM {system} WHERE type IN ('module', 'theme') ORDER BY filename ASC"; $rows = $this->connection->query($query)->fetchAllAssoc('filename'); $extensions = array(); foreach ($rows as $row) { $info = unserialize($row->info); if ($info['hidden']) { continue; } // See default values in _system_rebuild_module_data(). $extensions[$row->name] = ['filename' => $row->filename, 'type' => $row->type, 'slug' => $row->name, 'parent' => strlen($row->owner) ? $row->owner : null, 'enabled' => (bool) $row->status, 'name' => $info['name'], 'description' => $info['description'], 'package' => $info['package'], 'version' => $info['version'], 'required' => empty($info['required']) ? false : true, 'dependencies' => empty($info['dependencies']) ? array() : $info['dependencies'], 'project' => $info['project']]; } return $extensions; }
/** * {@inheritdoc} */ public function create($name, array $values = []) { $exists = (bool) $this->db->query("SELECT 1 FROM {umenu} WHERE name = ?", [$name])->fetchField(); if ($exists) { throw new \InvalidArgumentException(sprintf("%s: cannot create menu, already exists", $name)); } $values['name'] = $name; if (empty($values['title'])) { $values['title'] = $name; } unset($values['id']); $this->db->insert('umenu')->fields($values)->execute(); $menu = $this->load($name); if ($this->dispatcher) { $this->dispatcher->dispatch('menu:create', new GenericEvent($menu)); } return $menu; }
/** * {@inheritdoc} */ public function garbageCollection() { // Drop all messages for inactive subscriptions // FIXME: When volatile only $this->db->query("\n DELETE\n FROM {apb_queue}\n WHERE sub_id IN (\n SELECT id\n FROM {apb_sub}\n WHERE status = 0\n )\n "); // Clean up expired messages if (false) { $this->db->query("DELETE FROM {apb_msg} WHERE created < :time", array(':time' => time() - $this->context->messageMaxLifetime)); } // Limit queue size if configured for if (false) { $min = $this->db->query("\n SELECT msg_id\n FROM {apb_queue}\n ORDER BY msg_id DESC\n OFFSET :max LIMIT 1\n ", array(':max' => $this->context->queueGlobalLimit))->fetchField(); if ($min) { // If the same message exists in many queues, we will never // reach the exact global limit: deleting all messages with // a lower id ensures that we may be close enought to this // limit $this->db->query("DELETE FROM {apb_queue} WHERE msg_id < :min", array(':min' => $min)); } } // Clean up orphaned messages $this->db->query("\n DELETE FROM {apb_msg}\n WHERE id NOT IN (\n SELECT msg_id FROM {apb_queue}\n )\n "); }
public static function Log(Node $user, $action, Node $node1, $summary) { $type1 = $node1->getType(); $pk1 = $node1->pk; $context1 = $node1->context; // Escape the summary self::_EscapeString($summary); $date = date('Y-m-d G:i:s'); $sql = "INSERT INTO node_history (user_pk, user_context, pk1, type1, context1, action, date, summary) VALUES ($user->pk, $user->context, $pk1, '$type1', $context1, '$action', '$date', '$summary') "; $dbc = new DatabaseConnection(); $rows = $dbc->query($sql); return true; }
public function execute() { // @todo Select the proper database from Config if (MeshTools::$GlobalDebug) { MeshTools::$DebugCounter++; echo 'Q' . MeshTools::$DebugCounter . '==========>' . $this->_sql; error_log('Q' . MeshTools::$DebugCounter . '==========>' . $this->_sql); } $dbc = new DatabaseConnection(); return $dbc->query($this->_sql); }
public static function GetNodeTypes($mesh = null) { if (isset($mesh)) { $mesh .= '.'; } $sql = "SELECT TABLE_NAME FROM {$mesh}INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'pk' AND TABLE_NAME NOT LIKE '\_%' ORDER BY TABLE_NAME"; $dbc = new DatabaseConnection(); $types = $dbc->query($sql); foreach ($types as $type) { $t[] = $type['TABLE_NAME']; } return $t; }
function getBookData() { $_SESSION['bookid'] = $_GET['id']; $conn = new DatabaseConnection(); return $conn->query('CALL verLibro(' . $_GET['id'] . ')'); }
public function restoreUserFromUsername( DatabaseConnection $connection ) { if(!isset($connection) || !isset($this->username)) { $this->isAuthenticated = false; return$this->isAuthenticated; } if( !$connection->isConnected ) { if( !$connection->Connect() ){ return $this->isAuthenticated; } } $query = "select userId, username, userLevel, ipaddress, isLoggedIn, lastLogin from users where username='******';"; if( !$connection->query( $query ) ) { return $this->isAuthenticated; } if( 1 > $connection->getNumRows() ) { //echo "user {$query}"; //print_r($connection->getObject()); return $this->isAuthenticated; } $user = $connection->getObject(); $this->userLevel = $user->userLevel; $this->lastLogin = $user->lastLogin; $this->ipaddress = $user->ipaddress; $this->isAuthenticated = $user->isLoggedIn; }
/** * {@inheritdoc} */ public function getWhitelist() { return $this->db->query("SELECT DISTINCT SUBSTRING_INDEX(source, '/', 1) AS path FROM {url_alias}")->fetchCol(); }
public function delete() { switch ($_GET['type']) { case 'book': $conn = new DatabaseConnection(); $bookdata = $conn->query('SELECT picurl FROM libro WHERE id_libro = ' . $_GET['bid']); if ($bookdata[0]['picurl'] != 'view/img/icon-default-book.png') { unlink($bookdata[0]['picurl']); } $conn->query('DELETE FROM libro WHERE id_libro =' . $_GET['bid']); break; case 'author': $conn = new DatabaseConnection(); $bookdata = $conn->query('SELECT picurl FROM autor WHERE id_autor = ' . $_GET['aid']); if ($bookdata[0]['picurl'] != 'view/img/author/icon-user-default.png') { unlink($bookdata[0]['picurl']); } $conn->query('DELETE FROM autor WHERE id_autor =' . $_GET['aid']); break; case 'editorial': $conn = new DatabaseConnection(); $conn->query('DELETE FROM editorial WHERE id_editorial =' . $_GET['eid']); break; case 'genre': $conn = new DatabaseConnection(); $conn->query('DELETE FROM genero WHERE id_genero =' . $_GET['gid']); break; case 'reader': $conn = new DatabaseConnection(); $conn->query('DELETE FROM lector WHERE id_lector =' . $_GET['uid']); break; } }
public function searchBook($searchstring) { $conn = new DatabaseConnection(); $searchstring = $conn->quote('.*' . $searchstring . '.*'); return $conn->query('CALL searchBook(' . $searchstring . ')'); }
public function query($asarray) { $sql = $this->getSql(); if ($asarray) { $dbc = new DatabaseConnection(); $cluster = $dbc->query($sql); } else { // Handle cluster creation $cluster = new Cluster($this->_from['table']); $cluster->populate($this->_from['table'], $sql); } return $cluster; }
/** * @param $query * @return resource */ public function _exec_raw_query($query) { //print_r($query); $this->ConnectDatabase(); return $this->db->query($query); }
public function getAutorBooks($autor_id) { $conn = new DatabaseConnection(); return $conn->query('CALL librosAutor(' . $autor_id . ')'); }
public function query($query, array $args = array(), $options = array()) { return $this->connection->query($query, $args, $options); }
private function _linkExists($location, $pk1, $pk2) { try { $dbc = new DatabaseConnection(); $sql = "SELECT * FROM `$location` WHERE pk1 = $pk1 AND pk2 = $pk2"; $rows = $dbc->query($sql); if (count($rows)) { return true; } return false; } catch (Exception $e) { throw new Exception("Could not find link due to bad sql: $sql, ".$e->getMessage()); } }
public function populate($type, $sql) { try { $dbc = new DatabaseConnection(); $rows = $dbc->query($sql); $pks = array(); foreach ($rows as $row) { $pks[] = $row['pk']; } if (count($pks)) { $pks = implode(',', $pks); $plugin = "in:pk:$pks"; } else { $plugin = 'in:pk:0'; } $this->_callChain = new CallChain(); $this->_callChain->push($type, array($plugin)); $this->_cache->populate($rows); $this->_count = count($this->_cache); } catch (Exception $e) { throw $e; } }