本文整理汇总了PHP中DatabaseConnection::query方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::query方法的具体用法?PHP DatabaseConnection::query怎么用?PHP DatabaseConnection::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
/** @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);
}
示例2: destroySessions
/**
* @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;
}
示例3: cleanup
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 . "}");
}
}
}
示例4: testLastID
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()');
}
示例5: useNonce
/**
* {@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]);
}
示例6: uniqid
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;
}
示例7: refreshUserList
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));
}
示例8: delete
/**
* 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);
}
}
示例9: getUserList
public function getUserList()
{
$dbconn = new DatabaseConnection('localhost', 'user', 'password');
$results = $dbconn->query('select name from user');
sort($results);
return $results;
}
示例10: getListaUsuario
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;
}
示例11: submitComment
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);
}
示例12: getUserList
public function getUserList()
{
$server = "localhost";
$user = "user";
$password = "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;
}
}
示例13: getExtensions
/**
* @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;
}
示例14: create
/**
* {@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;
}
示例15: garbageCollection
/**
* {@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 ");
}