Exemplo n.º 1
0
function sqx($query, $showerrors = true)
{
    global $dbutils_show_errors;
    $dbutils_show_errors = @$showerrors;
    if (!is_object($query)) {
        if (is_array($query)) {
            foreach ($query as $key => $val) {
                if (sqlWriteStatement($val)) {
                    assertDataNonRO('sq:' . $val);
                }
            }
        } else {
            if (sqlWriteStatement($query)) {
                assertDataNonRO('sq:' . $query);
            }
        }
        $query = new Q($query);
    }
    return $query->error();
}
Exemplo n.º 2
0
 public function __construct($queryString, $stack_trace_level = 0)
 {
     global $dbutils_show_errors;
     global $dbutils_link;
     $this->n = 0;
     $this->insert_id = false;
     $this->cached_count = false;
     $this->sql = $queryString;
     if (!dbiutils_assert_connection($stack_trace_level)) {
         if (!$dbutils_show_errors) {
             throw new Exception('No link when trying: ' . $queryString);
             // Exception is to emulate previous die() behavior for compatibility
         } else {
             dbiutils_stack_trace('No link when trying: ' . $queryString, 0 + @$stack_trace_level);
             // Letting this continue for compatibility
         }
     }
     if (is_array($queryString)) {
         $qc = 0;
         foreach ($queryString as $key => $val) {
             $qc++;
             if ('' . @$val > '') {
                 if (sqlWriteStatement($val)) {
                     assertDataNonRO('sq:' . $val);
                 }
             } else {
                 dbiutils_stack_trace('No SQL statement given in array (item #' . $qc . ')', 0 + @$stack_trace_level);
             }
         }
         if ($qc == 0) {
             dbiutils_stack_trace('No SQL statement given in array', 0 + @$stack_trace_level);
         }
         $this->moreResults = array();
         $this->moreErrors = array();
         $combinedQueryString = implode(';', $queryString);
         mysqli_multi_query($dbutils_link, $combinedQueryString);
         $this->result = mysqli_use_result($dbutils_link);
         $this->error = mysqli_error($dbutils_link);
         while (mysqli_more_results($dbutils_link) && mysqli_next_result($dbutils_link)) {
             $this->moreResults[] = mysqli_use_result($dbutils_link);
             $this->moreErrors[] = mysqli_error($dbutils_link);
         }
     } else {
         $combinedQueryString = '' . @$queryString;
         if ('' . @$queryString == '') {
             dbiutils_stack_trace('No SQL statement given', 0 + @$stack_trace_level);
         }
         $sample = strtolower(trim(substr($queryString, 1, 7)));
         $this->moreResults = array();
         $this->moreErrors = array();
         $this->result = mysqli_query($dbutils_link, $queryString);
         $this->error = mysqli_error($dbutils_link);
         if ($sample == 'insert') {
             $this->insert_id = mysqli_insert_id($dbutils_link);
         }
     }
     if ('' . @$this->error > '') {
         $this->result = null;
         throw new Exception('MySQL: ' . $this->error . '  [QUERY: ' . $combinedQueryString . ']');
     }
 }