Esempio n. 1
0
 /** Custom SQL Query **/
 function query($query, $singleResult = 0)
 {
     $this->_result = mysqli_query($query, $this->_dbHandle);
     if (preg_match("/select/i", $query)) {
         $result = array();
         $table = array();
         $field = array();
         $tempResults = array();
         $numOfFields = mysqli_num_fields($this->_result);
         for ($i = 0; $i < $numOfFields; ++$i) {
             array_push($table, mysqli_field_table($this->_result, $i));
             array_push($field, mysqli_field_name($this->_result, $i));
         }
         while ($row = mysqli_fetch_row($this->_result)) {
             for ($i = 0; $i < $numOfFields; ++$i) {
                 $table[$i] = trim(ucfirst($table[$i]), "s");
                 $tempResults[$table[$i]][$field[$i]] = $row[$i];
             }
             if ($singleResult == 1) {
                 mysqli_free_result($this->_result);
                 return $tempResults;
             }
             array_push($result, $tempResults);
         }
         mysqli_free_result($this->_result);
         return $result;
     }
 }
 /**
  * Returns information about a table or a result set.
  *
  * WARNING: this method will probably not work because the mysqli_*()
  * functions it relies upon may not exist.
  *
  * @param object|string  $result  DB_result object from a query or a
  *                                string containing the name of a table
  * @param int            $mode    a valid tableInfo mode
  * @return array  an associative array with the information requested
  *                or an error object if something is wrong
  * @access public
  * @internal
  * @see DB_common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (isset($result->result)) {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->result;
         $got_string = false;
     } elseif (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         $id = @mysqli_list_fields($this->dsn['database'], $result, $this->connection);
         $got_string = true;
     } else {
         /*
          * Probably received a result resource identifier.
          * Copy it.
          * Depricated.  Here for compatibility only.
          */
         $id = $result;
         $got_string = false;
     }
     if (!is_resource($id)) {
         return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA);
     }
     if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     $count = @mysqli_num_fields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (!$mode) {
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = $case_func(@mysqli_field_table($id, $i));
             $res[$i]['name'] = $case_func(@mysqli_field_name($id, $i));
             $res[$i]['type'] = @mysqli_field_type($id, $i);
             $res[$i]['len'] = @mysqli_field_len($id, $i);
             $res[$i]['flags'] = @mysqli_field_flags($id, $i);
         }
     } else {
         // full
         $res['num_fields'] = $count;
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = $case_func(@mysqli_field_table($id, $i));
             $res[$i]['name'] = $case_func(@mysqli_field_name($id, $i));
             $res[$i]['type'] = @mysqli_field_type($id, $i);
             $res[$i]['len'] = @mysqli_field_len($id, $i);
             $res[$i]['flags'] = @mysqli_field_flags($id, $i);
             if ($mode & DB_TABLEINFO_ORDER) {
                 $res['order'][$res[$i]['name']] = $i;
             }
             if ($mode & DB_TABLEINFO_ORDERTABLE) {
                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
             }
         }
     }
     // free the result only if we were called on a table
     if ($got_string) {
         @mysqli_free_result($id);
     }
     return $res;
 }
Esempio n. 3
0
 function print_result($RESULT)
 {
     if (!$RESULT) {
         return;
     }
     if (mysqli_num_rows($RESULT) < 1) {
         return;
     }
     $fieldcount = mysqli_num_fields($RESULT);
     for ($i = 0; $i < $fieldcount; $i++) {
         $tables[mysqli_field_table($RESULT, $i)]++;
     }
     print '
         <style type="text/css">
             .rs_tb_th {
                 font-family: Verdana;
                 font-size:9pt;
                 font-weight:bold;
                 color:white;
             }
             .rs_f_th {
                 font-family:Verdana;
                 font-size:7pt;
                 font-weight:bold;
                 color:white;
             }
             .rs_td {
                 font-family:Verdana;
                 font-size:7pt;
             }
         </style>
         <script type="text/javascript" language="JavaScript">
             var lastID;
             function highlight(id) {
                 if(lastID) {
                     lastID.style.color = "#000000";
                     lastID.style.textDecoration = "none";
                 }
                 tdToHighlight = document.getElementById(id);
                 tdToHighlight.style.color ="#FF0000";
                 tdToHighlight.style.textDecoration = "underline";
                 lastID = tdToHighlight;
             }
         </script>
     ';
     print '<table bgcolor="#000000" cellspacing="1" cellpadding="1">';
     print '<tr>';
     foreach ($tables as $tableName => $tableCount) {
         $col == '0054A6' ? $col = '003471' : ($col = '0054A6');
         print '<th colspan="' . $tableCount . '" class="rs_tb_th" style="background-color:#' . $col . ';">' . $tableName . '</th>';
     }
     print '</tr>';
     print '<tr>';
     for ($i = 0; $i < mysqli_num_fields($RESULT); $i++) {
         $FIELD = mysqli_field_name($RESULT, $i);
         $col == '0054A6' ? $col = '003471' : ($col = '0054A6');
         print '<td align="center" bgcolor="#' . $col . '" class="rs_f_th">' . $FIELD . '</td>';
     }
     print '</tr>';
     mysqli_data_seek($RESULT, 0);
     while ($DB_ROW = mysqli_fetch_array($RESULT, MYSQLI_NUM)) {
         $pointer++;
         if ($toggle) {
             $col1 = "E6E6E6";
             $col2 = "DADADA";
         } else {
             $col1 = "E1F0FF";
             $col2 = "DAE8F7";
         }
         $toggle = !$toggle;
         print '<tr id="ROW' . $pointer . '" onMouseDown="highlight(\'ROW' . $pointer . '\');">';
         foreach ($DB_ROW as $value) {
             $col == $col1 ? $col = $col2 : ($col = $col1);
             print '<td valign="top" bgcolor="#' . $col . '" class="rs_td" nowrap>' . nl2br($value) . '</td>';
         }
         print '</tr>';
     }
     print '</table>';
     mysqli_data_seek($RESULT, 0);
 }