Ejemplo n.º 1
0
 /** @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);
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }
Ejemplo n.º 3
0
 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()');
 }
Ejemplo n.º 5
0
 /**
  * {@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]);
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 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));
 }
Ejemplo n.º 8
0
 /**
  * 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);
     }
 }
Ejemplo n.º 9
0
 public function getUserList()
 {
     $dbconn = new DatabaseConnection('localhost', 'user', 'password');
     $results = $dbconn->query('select name from user');
     sort($results);
     return $results;
 }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
0
 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;
     }
 }
Ejemplo n.º 13
0
 /**
  * @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;
 }
Ejemplo n.º 14
0
 /**
  * {@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;
 }
Ejemplo n.º 15
0
 /**
  * {@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            ");
 }
Ejemplo n.º 16
0
    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;
    }
Ejemplo n.º 17
0
    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);
    }
Ejemplo n.º 18
0
    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;
    }
Ejemplo n.º 19
0
 function getBookData()
 {
     $_SESSION['bookid'] = $_GET['id'];
     $conn = new DatabaseConnection();
     return $conn->query('CALL verLibro(' . $_GET['id'] . ')');
 }
Ejemplo n.º 20
0
	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();
 }
Ejemplo n.º 22
0
 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;
     }
 }
Ejemplo n.º 23
0
 public function searchBook($searchstring)
 {
     $conn = new DatabaseConnection();
     $searchstring = $conn->quote('.*' . $searchstring . '.*');
     return $conn->query('CALL searchBook(' . $searchstring . ')');
 }
Ejemplo n.º 24
0
    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;
    }
Ejemplo n.º 25
0
 /**
  * @param $query
  * @return resource
  */
 public function _exec_raw_query($query)
 {
     //print_r($query);
     $this->ConnectDatabase();
     return $this->db->query($query);
 }
Ejemplo n.º 26
0
 public function getAutorBooks($autor_id)
 {
     $conn = new DatabaseConnection();
     return $conn->query('CALL librosAutor(' . $autor_id . ')');
 }
Ejemplo n.º 27
0
 public function query($query, array $args = array(), $options = array())
 {
     return $this->connection->query($query, $args, $options);
 }
Ejemplo n.º 28
0
    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());
        }

    }
Ejemplo n.º 29
0
    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;
        }
    }