Пример #1
0
/**
 * runs a query and returns the result
 *
 * @param string $query query to run
 * @param resource $link mysql link resource
 * @param integer $options
 * @return mixed
 */
function PMA_DBI_try_query($query, $link = null, $options = 0)
{
    if (empty($link)) {
        if (isset($GLOBALS['userlink'])) {
            $link = $GLOBALS['userlink'];
        } else {
            return false;
        }
    }
    if ($GLOBALS['cfg']['DBG']['sql']) {
        $time = microtime(true);
    }
    if ($options == ($options | PMA_DBI_QUERY_STORE)) {
        $r = mysql_query($query, $link);
    } elseif ($options == ($options | PMA_DBI_QUERY_UNBUFFERED)) {
        $r = mysql_unbuffered_query($query, $link);
    } else {
        $r = mysql_query($query, $link);
    }
    if ($GLOBALS['cfg']['DBG']['sql']) {
        $time = microtime(true) - $time;
        $hash = md5($query);
        if (isset($_SESSION['debug']['queries'][$hash])) {
            $_SESSION['debug']['queries'][$hash]['count']++;
        } else {
            $_SESSION['debug']['queries'][$hash] = array();
            $_SESSION['debug']['queries'][$hash]['count'] = 1;
            $_SESSION['debug']['queries'][$hash]['query'] = $query;
            $_SESSION['debug']['queries'][$hash]['time'] = $time;
        }
        $trace = array();
        foreach (debug_backtrace() as $trace_step) {
            $trace[] = PMA_Error::relPath($trace_step['file']) . '#' . $trace_step['line'] . ': ' . (isset($trace_step['class']) ? $trace_step['class'] : '') . (isset($trace_step['type']) ? $trace_step['type'] : '') . (isset($trace_step['function']) ? $trace_step['function'] : '') . '(' . (isset($trace_step['params']) ? implode(', ', $trace_step['params']) : '') . ')';
        }
        $_SESSION['debug']['queries'][$hash]['trace'][] = $trace;
    }
    if ($r != FALSE && PMA_Tracker::isActive() == TRUE) {
        PMA_Tracker::handleQuery($query);
    }
    return $r;
}
/**
 * runs a query and returns the result
 *
 * @param string   $query               query to run
 * @param resource $link                mysql link resource
 * @param integer  $options             query options
 * @param bool     $cache_affected_rows whether to cache affected row
 *
 * @return mixed
 */
function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_rows = true)
{
    if (empty($link)) {
        if (isset($GLOBALS['userlink'])) {
            $link = $GLOBALS['userlink'];
        } else {
            return false;
        }
    }
    if ($GLOBALS['cfg']['DBG']['sql']) {
        $time = microtime(true);
    }
    $r = PMA_DBI_real_query($query, $link, $options);
    if ($cache_affected_rows) {
        $GLOBALS['cached_affected_rows'] = PMA_DBI_affected_rows($link, $get_from_cache = false);
    }
    if ($GLOBALS['cfg']['DBG']['sql']) {
        $time = microtime(true) - $time;
        $hash = md5($query);
        if (isset($_SESSION['debug']['queries'][$hash])) {
            $_SESSION['debug']['queries'][$hash]['count']++;
        } else {
            $_SESSION['debug']['queries'][$hash] = array();
            if ($r == false) {
                $_SESSION['debug']['queries'][$hash]['error'] = '<b style="color:red">' . mysqli_error($link) . '</b>';
            }
            $_SESSION['debug']['queries'][$hash]['count'] = 1;
            $_SESSION['debug']['queries'][$hash]['query'] = $query;
            $_SESSION['debug']['queries'][$hash]['time'] = $time;
        }
        $trace = array();
        foreach (debug_backtrace() as $trace_step) {
            $trace[] = PMA_Error::relPath($trace_step['file']) . '#' . $trace_step['line'] . ': ' . (isset($trace_step['class']) ? $trace_step['class'] : '') . (isset($trace_step['type']) ? $trace_step['type'] : '') . (isset($trace_step['function']) ? $trace_step['function'] : '') . '(' . (isset($trace_step['params']) ? implode(', ', $trace_step['params']) : '') . ')';
        }
        $_SESSION['debug']['queries'][$hash]['trace'][] = $trace;
    }
    if ($r != false && PMA_Tracker::isActive() == true) {
        PMA_Tracker::handleQuery($query);
    }
    return $r;
}
 /**
  * log error to configured log facility
  *
  * @param PMA_Error $error the error
  *
  * @return bool
  *
  * @todo finish!
  */
 protected function logError($error)
 {
     return error_log($error->getMessage());
 }
Пример #4
0
 /**
  * Stores query data into session data for debugging purposes
  *
  * @param string   $query  Query text
  * @param resource $link   database link
  * @param resource $result Query result
  * @param integer  $time   Time to execute query
  *
  * @return void
  */
 private function _dbgQuery($query, $link, $result, $time)
 {
     $hash = md5($query);
     if (isset($_SESSION['debug']['queries'][$hash])) {
         $_SESSION['debug']['queries'][$hash]['count']++;
     } else {
         $_SESSION['debug']['queries'][$hash] = array();
         if ($result == false) {
             $_SESSION['debug']['queries'][$hash]['error'] = '<b style="color:red">' . mysqli_error($link) . '</b>';
         }
         $_SESSION['debug']['queries'][$hash]['count'] = 1;
         $_SESSION['debug']['queries'][$hash]['query'] = $query;
         $_SESSION['debug']['queries'][$hash]['time'] = $time;
     }
     $trace = array();
     foreach (debug_backtrace() as $trace_step) {
         $trace[] = (isset($trace_step['file']) ? PMA_Error::relPath($trace_step['file']) : '') . (isset($trace_step['line']) ? '#' . $trace_step['line'] . ': ' : '') . (isset($trace_step['class']) ? $trace_step['class'] : '') . (isset($trace_step['type']) ? $trace_step['type'] : '') . (isset($trace_step['function']) ? $trace_step['function'] : '') . '(' . (isset($trace_step['params']) ? implode(', ', $trace_step['params']) : '') . ')';
     }
     $_SESSION['debug']['queries'][$hash]['trace'][] = $trace;
 }
/**
 * Error handler to catch fatal errors when loading configuration
 * file
 *
 * @return void
 */
function PMA_Config_fatalErrorHandler()
{
    if (isset($GLOBALS['pma_config_loading']) && $GLOBALS['pma_config_loading']) {
        $error = error_get_last();
        if ($error !== null) {
            PMA_fatalError(sprintf('Failed to load phpMyAdmin configuration (%s:%s): %s', PMA_Error::relPath($error['file']), $error['line'], $error['message']));
        }
    }
}
 /**
  * Stores query data into session data for debugging purposes
  *
  * @param string         $query  Query text
  * @param object         $link   database link
  * @param object|boolean $result Query result
  * @param integer        $time   Time to execute query
  *
  * @return void
  */
 private function _dbgQuery($query, $link, $result, $time)
 {
     $dbgInfo = array();
     $error_message = $this->getError($link);
     if ($result == false && is_string($error_message)) {
         $dbgInfo['error'] = '<span style="color:red">' . htmlspecialchars($error_message) . '</span>';
     }
     $dbgInfo['query'] = htmlspecialchars($query);
     $dbgInfo['time'] = $time;
     // Get and slightly format backtrace
     $dbgInfo['trace'] = debug_backtrace();
     foreach ($dbgInfo['trace'] as $key => $step) {
         if (isset($step['file'])) {
             $dbgInfo['trace'][$key]['file'] = PMA_Error::relPath($step['file']);
         }
     }
     $dbgInfo['hash'] = md5($query);
     $_SESSION['debug']['queries'][] = $dbgInfo;
 }
Пример #7
0
/**
 * runs a query and returns the result
 *
 * @uses    PMA_DBI_QUERY_STORE
 * @uses    PMA_DBI_QUERY_UNBUFFERED
 * @uses    $GLOBALS['userlink']
 * @uses    MYSQLI_STORE_RESULT
 * @uses    MYSQLI_USE_RESULT
 * @uses    mysqli_query()
 * @uses    defined()
 * @param   string          $query      query to execute
 * @param   object mysqli   $link       mysqli object
 * @param   integer         $options
 * @param   boolean         $cache_affected_rows
 * @return  mixed           true, false or result object
 */
function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_rows = true)
{
    if ($options == ($options | PMA_DBI_QUERY_STORE)) {
        $method = MYSQLI_STORE_RESULT;
    } elseif ($options == ($options | PMA_DBI_QUERY_UNBUFFERED)) {
        $method = MYSQLI_USE_RESULT;
    } else {
        $method = 0;
    }
    if (empty($link)) {
        if (isset($GLOBALS['userlink'])) {
            $link = $GLOBALS['userlink'];
        } else {
            return false;
        }
    }
    if ($GLOBALS['cfg']['DBG']['sql']) {
        $time = microtime(true);
    }
    $r = mysqli_query($link, $query, $method);
    if ($cache_affected_rows) {
        $GLOBALS['cached_affected_rows'] = PMA_DBI_affected_rows($link, $get_from_cache = false);
    }
    if ($GLOBALS['cfg']['DBG']['sql']) {
        $time = microtime(true) - $time;
        $hash = md5($query);
        if (isset($_SESSION['debug']['queries'][$hash])) {
            $_SESSION['debug']['queries'][$hash]['count']++;
        } else {
            $_SESSION['debug']['queries'][$hash] = array();
            $_SESSION['debug']['queries'][$hash]['count'] = 1;
            $_SESSION['debug']['queries'][$hash]['query'] = $query;
            $_SESSION['debug']['queries'][$hash]['time'] = $time;
        }
        $trace = array();
        foreach (debug_backtrace() as $trace_step) {
            $trace[] = PMA_Error::relPath($trace_step['file']) . '#' . $trace_step['line'] . ': ' . (isset($trace_step['class']) ? $trace_step['class'] : '') . (isset($trace_step['type']) ? $trace_step['type'] : '') . (isset($trace_step['function']) ? $trace_step['function'] : '') . '(' . (isset($trace_step['params']) ? implode(', ', $trace_step['params']) : '') . ')';
        }
        $_SESSION['debug']['queries'][$hash]['trace'][] = $trace;
    }
    if ($r != FALSE && PMA_Tracker::isActive() == TRUE) {
        PMA_Tracker::handleQuery($query);
    }
    return $r;
    // From the PHP manual:
    // "note: returns true on success or false on failure. For SELECT,
    // SHOW, DESCRIBE or EXPLAIN, mysqli_query() will return a result object"
    // so, do not use the return value to feed mysqli_num_rows() if it's
    // a boolean
}
 /**
  * Stores query data into session data for debugging purposes
  *
  * @param string         $query  Query text
  * @param object         $link   database link
  * @param object|boolean $result Query result
  * @param integer        $time   Time to execute query
  *
  * @return void
  */
 private function _dbgQuery($query, $link, $result, $time)
 {
     $hash = md5($query);
     if (isset($_SESSION['debug']['queries'][$hash])) {
         $_SESSION['debug']['queries'][$hash]['count']++;
     } else {
         $_SESSION['debug']['queries'][$hash] = array();
         $error_message = $this->getError($link);
         if ($result == false && is_string($error_message)) {
             $_SESSION['debug']['queries'][$hash]['error'] = '<b style="color:red">' . htmlspecialchars($error_message) . '</b>';
         }
         $_SESSION['debug']['queries'][$hash]['count'] = 1;
         $_SESSION['debug']['queries'][$hash]['query'] = htmlspecialchars($query);
         $_SESSION['debug']['queries'][$hash]['time'] = $time;
     }
     $_SESSION['debug']['queries'][$hash]['trace'][] = PMA_Error::formatBacktrace(debug_backtrace(), " ", "\n");
 }
Пример #9
0
 /**
  * Get a single function argument
  *
  * if $function is one of include/require
  * the $arg is converted to a relative path
  *
  * @param string $arg      argument to process
  * @param string $function function name
  *
  * @return string
  */
 public static function getArg($arg, $function)
 {
     $retval = '';
     $include_functions = array('include', 'include_once', 'require', 'require_once');
     $connect_functions = array('mysql_connect', 'mysql_pconnect', 'mysqli_connect', 'mysqli_real_connect', 'connect', '_realConnect');
     if (in_array($function, $include_functions)) {
         $retval .= PMA_Error::relPath($arg);
     } elseif (in_array($function, $connect_functions) && getType($arg) === 'string') {
         $retval .= getType($arg) . ' ********';
     } elseif (is_scalar($arg)) {
         $retval .= getType($arg) . ' ' . htmlspecialchars(var_export($arg, true));
     } else {
         $retval .= getType($arg);
     }
     return $retval;
 }
Пример #10
0
 /**
  * Get a single function argument
  *
  * if $function is one of include/require
  * the $arg is converted to a relative path
  *
  * @param string $arg
  * @param string $function
  *
  * @return string
  */
 protected function getArg($arg, $function)
 {
     $retval = '';
     $include_functions = array('include', 'include_once', 'require', 'require_once');
     if (in_array($function, $include_functions)) {
         $retval .= PMA_Error::relPath($arg);
     } elseif (is_scalar($arg)) {
         $retval .= getType($arg) . ' ' . htmlspecialchars($arg);
     } else {
         $retval .= getType($arg);
     }
     return $retval;
 }
Пример #11
0
 /**
  * Display a single function argument
  * if $function is one of include/require the $arg is converted te relative path
  *
  * @param string $arg
  * @param string $function
  *
  * @return void
  */
 protected function displayArg($arg, $function)
 {
     $include_functions = array('include', 'include_once', 'require', 'require_once');
     if (in_array($function, $include_functions)) {
         echo PMA_Error::relPath($arg);
     } elseif (is_scalar($arg)) {
         echo gettype($arg) . ' ' . htmlspecialchars($arg);
     } else {
         echo gettype($arg);
     }
 }
Пример #12
0
/**
 * runs a query and returns the result
 *
 * @param string $query query to run
 * @param resource $link mysql link resource
 * @param integer $options
 * @return mixed
 */
function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_rows = true)
{
    //print_r($query);
    if (empty($link)) {
        if (isset($GLOBALS['userlink'])) {
            $link = $GLOBALS['userlink'];
        } else {
            return false;
        }
    }
    if ($GLOBALS['cfg']['DBG']['sql']) {
        $time = microtime(true);
    }
    /*
        if ($options == ($options | PMA_DBI_QUERY_STORE)) {
            $r = mysql_query($query, $link);
        } elseif ($options == ($options | PMA_DBI_QUERY_UNBUFFERED)) {
            $r = mysql_unbuffered_query($query, $link);
        } else {
            $r = mysql_query($query, $link);
        }
    */
    $stid = oci_parse($link, $query);
    if (!$stid) {
        $e = oci_error($link);
        // For oci_execute errors pass the statement handle
        PMA_mysqlDie($e['message'], $query);
    }
    $result_sql = oci_execute($stid);
    if (!$result_sql) {
        $e = oci_error($stid);
        // For oci_execute errors pass the statement handle
        //$error_str = ($e['message'])
        //. ($e['sqltext']);
        $sql_str = substr_replace($e['sqltext'], '^', $e['offset'], 0);
        PMA_mysqlDie($e['message'], $sql_str);
    }
    $r = $stid;
    if ($cache_affected_rows) {
        $GLOBALS['cached_affected_rows'] = PMA_DBI_affected_rows($r, $get_from_cache = false);
    }
    if ($GLOBALS['cfg']['DBG']['sql']) {
        $time = microtime(true) - $time;
        $hash = md5($query);
        if (isset($_SESSION['debug']['queries'][$hash])) {
            $_SESSION['debug']['queries'][$hash]['count']++;
        } else {
            $_SESSION['debug']['queries'][$hash] = array();
            $_SESSION['debug']['queries'][$hash]['count'] = 1;
            $_SESSION['debug']['queries'][$hash]['query'] = $query;
            $_SESSION['debug']['queries'][$hash]['time'] = $time;
        }
        $trace = array();
        foreach (debug_backtrace() as $trace_step) {
            $trace[] = PMA_Error::relPath($trace_step['file']) . '#' . $trace_step['line'] . ': ' . (isset($trace_step['class']) ? $trace_step['class'] : '') . (isset($trace_step['type']) ? $trace_step['type'] : '') . (isset($trace_step['function']) ? $trace_step['function'] : '') . '(' . (isset($trace_step['params']) ? implode(', ', $trace_step['params']) : '') . ')';
        }
        $_SESSION['debug']['queries'][$hash]['trace'][] = $trace;
    }
    if ($r != FALSE && PMA_Tracker::isActive() == TRUE) {
        PMA_Tracker::handleQuery($query);
    }
    return $r;
}