Database::doQuery PHP Method

doQuery() protected method

Execute actual queries. Within this class, this function should be used to do queries, not the wrapper function query(). The logger will log the caller of the caller of this function. So there should be one function in between this and outside this class.
protected doQuery ( $sql ) : MySQL
return MySQL resource|false
    protected function doQuery($sql)
    {
        $microtimeStart = microtime(true);
        $queryResponse = $this->conn->query($sql);
        if (!$this->ignoreErrors && ($queryResponse === false || $this->lastErrNo())) {
            throw new SwarmException('Error in doQuery: ' . $this->lastErrMsg());
        }
        $this->logQuery($sql, $queryResponse, $microtimeStart);
        return $queryResponse;
    }

Usage Example

Example #1
0
function logAccess()
{
    define('_VALID_CODE', true);
    include_once 'database.php';
    $dbh = new Database();
    $dbh->init();
    $ipaddr_base = $_SERVER['REMOTE_ADDR'];
    if (is_array($ipaddr_base)) {
        $ipaddr = $ipaddr_base[0];
    } else {
        $ipaddr = $ipaddr_base;
    }
    //echo("--> " . $ipaddr);
    $query = "SELECT * FROM downloads26 WHERE ipaddr = '{$ipaddr}';";
    $result = $dbh->doQuery($query);
    if (mysql_num_rows(&$result) > 0) {
        /*$row = mysql_fetch_array(&$result);
        
                if (intval( $row['attempts'] ) > 50)
                {
                    die("Sorry, you've attempted to download StealthBot too many times. Please contact Stealth by <a href='mailto:[email protected]'>email</a> if you need another copy, or if you received this message in error.");
                } */
        $query = "UPDATE downloads26 SET attempts=attempts+1 WHERE ipaddr='{$ipaddr}';";
    } else {
        $query = "INSERT INTO downloads26(ipaddr, attempts) VALUES('{$ipaddr}', 1);";
    }
    mysql_free_result($result);
    $result = $dbh->doQuery($query);
}
All Usage Examples Of Database::doQuery