Ejemplo 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;
     }
 }
Ejemplo n.º 2
0
 function field_name() {
    $jml = $this->num_field();
    for($i = 0; $i < $jml; $i++) {
       $arr_field[] = mysqli_field_name($this->hasil, $i);
    }
    return $arr_field;
 }
Ejemplo n.º 3
0
function downloadProceed()
{
    if (isset($_GET["option"]) && $_GET["option"] != "") {
        $option = $_GET["option"];
        if ($option == "songs") {
            $query = 'SELECT title, artist, requestor FROM song_requests';
        } elseif ($option == "invites") {
            $query = 'SELECT firstname, lastname, guest_id, additional, requests FROM guests';
        } elseif ($option == "attending") {
            $query = 'SELECT firstname, lastname, guest_id, additional, additional_confirmed, requests, requests_confirmed, rsvp_time FROM guests WHERE attending = 1';
        } else {
            die("Invalid option provided.");
        }
        include_once "../../../includes/sql.inc.php";
        $db = new mysqli("localhost", DB_USER, DB_PASSWORD, "mccownwedding");
        $result = $db->query($query);
        if (!$result) {
            die('Couldn\'t fetch records');
        }
        $num_fields = mysqli_num_fields($result);
        $headers = array();
        for ($i = 0; $i < $num_fields; $i++) {
            $headers[] = mysqli_field_name($result, $i);
        }
        $fp = fopen('php://output', 'w');
        if ($fp && $result) {
            header('Content-Type: text/csv');
            header('Content-Disposition: attachment; filename="' . $option . '.csv"');
            header('Pragma: no-cache');
            header('Expires: 0');
            fputcsv($fp, $headers);
            while ($row = $result->fetch_array(MYSQLI_NUM)) {
                fputcsv($fp, array_values($row));
            }
            die;
        }
    }
}
Ejemplo n.º 4
0
 public function field_name($res, $field)
 {
     return @mysqli_field_name($res, $field);
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
Ejemplo n.º 6
0
function recuperaIdDado($tabela, $id)
{
    $con = bancoMysqli();
    //recupera os nomes dos campos
    $sql = "SELECT * FROM {$tabela}";
    $query = mysqli_query($con, $sql);
    $campo01 = mysqli_field_name($query, 0);
    $campo02 = mysqli_field_name($query, 1);
    $sql = "SELECT * FROM {$tabela} WHERE {$campo01} = {$id}";
    $query = mysql_query($sql);
    $campo = mysql_fetch_array($query);
    return $campo[$campo02];
}
function print_computers_real($systemid)
{
    global $l, $list_fields, $list_col_cant_del, $default_fields, $tab_options, $protectedPost;
    if (isset($protectedPost["actshowgroup"]) and $protectedPost["modify"] != "") {
        foreach ($protectedPost as $key => $val) {
            //check65422
            if (substr($key, 0, 5) == "check") {
                update_computer_group(substr($key, 5), $systemid, $protectedPost["actshowgroup"]);
            }
        }
        $tab_options['CACHE'] = 'RESET';
    }
    //group 2.0 version
    $sql_group = "SELECT xmldef FROM groups WHERE hardware_id='%s'";
    $arg = $systemid;
    $resGroup = mysql2_query_secure($sql_group, $_SESSION['OCS']["readServer"], $arg);
    $valGroup = mysqli_fetch_array($resGroup);
    //group old version
    if (!$valGroup["xmldef"]) {
        $sql_group = "SELECT request FROM groups WHERE hardware_id='%s'";
        $arg = $systemid;
        $resGroup = mysql2_query_secure($sql_group, $_SESSION['OCS']["readServer"], $arg);
        $valGroup = mysqli_fetch_array($resGroup);
        $request = $valGroup["request"];
        $tab_id = array();
        $result_value = mysqli_query($_SESSION['OCS']["readServer"], $request) or die(mysqli_error($_SESSION['OCS']["readServer"]));
        $fied_id_name = mysqli_field_name($result_value, 0);
        while ($value = mysqli_fetch_array($result_value)) {
            $tab_id[] = $value[$fied_id_name];
        }
    } else {
        $tab_list_sql = regeneration_sql($valGroup["xmldef"]);
        $i = 1;
        $tab_id = array();
        while ($tab_list_sql[$i]) {
            if ($tab_id != array()) {
                if (strtolower(substr($tab_list_sql[$i], 0, 19)) == "select distinct id ") {
                    $tab_list_sql[$i] .= " and id in (" . implode(",", $tab_id) . ")";
                } else {
                    $tab_list_sql[$i] .= " and hardware_id in (" . implode(",", $tab_id) . ")";
                }
                unset($tab_id);
            }
            $result_value = mysqli_query($_SESSION['OCS']["readServer"], xml_decode($tab_list_sql[$i])) or die(mysqli_error($_SESSION['OCS']["readServer"]));
            while ($value = mysqli_fetch_array($result_value)) {
                $tab_id[] = $value["HARDWARE_ID"];
            }
            $i++;
        }
    }
    if ($tab_id == array()) {
        msg_warning($l->g(766));
        return false;
    }
    $form_name = "calcul_computer_groupcache";
    $table_name = $form_name;
    echo "<font color=red><b>" . $l->g(927) . "</b></font>";
    echo open_form($form_name);
    $queryDetails = "SELECT ";
    foreach ($list_fields as $lbl => $value) {
        $queryDetails .= $value . ",";
    }
    $queryDetails = substr($queryDetails, 0, -1) . " FROM  hardware h LEFT JOIN accountinfo a ON a.hardware_id=h.id\n\t\t\t\t\t\twhere h.id in (" . implode(",", $tab_id) . ") and deviceid <> '_SYSTEMGROUP_' \n\t\t\t\t\t\t\t\t\t\tAND deviceid <> '_DOWNLOADGROUP_'";
    if (isset($mesmachines) and $mesmachines != '') {
        $queryDetails .= $mesmachines;
    }
    $tab_options['FILTRE'] = array('h.NAME' => 'Nom');
    $tab_options['form_name'] = $form_name;
    $tab_options['table_name'] = $table_name;
    ajaxtab_entete_fixe($list_fields, $default_fields, $tab_options, $list_col_cant_del);
    form_action_group($systemid);
    echo close_form();
    if (AJAX) {
        ob_end_clean();
        tab_req($list_fields, $default_fields, $list_col_cant_del, $queryDetails, $tab_options);
        ob_start();
    }
}
Ejemplo n.º 8
0
 if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
 }
 //******************************
 //   select all rows
 //******************************
 $imploded_ids = implode($_POST['exported']);
 //$sql = "SELECT * FROM TblCows WHERE id IN '$table_id'";
 //******************************
 //  create csv file
 //******************************
 $select = "SELECT * FROM TblCows WHERE id IN '{$table_id}'";
 $export = mysqli_query($select) or die("Sql error : " . mysqli_error());
 $fields = mysqli_num_fields($export);
 for ($i = 0; $i < $fields; $i++) {
     $header .= mysqli_field_name($export, $i) . ",";
 }
 while ($row = mysqli_fetch_row($export)) {
     $line = '';
     foreach ($row as $value) {
         if (!isset($value) || $value == "") {
             $value = "\t";
         } else {
             $value = str_replace('"', '""', $value);
             $value = '"' . $value . '"' . ",";
         }
         $line .= $value;
     }
     $data .= trim($line) . "\n";
 }
 $data = str_replace("\r", "", $data);
Ejemplo n.º 9
0
 function Table($query, $prop = array())
 {
     //    global $db;
     //    $rows = $db->selectComplex($query);
     //Issue query
     $link = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
     $res = mysqli_query($link, $query) or die('Error: ' . mysqli_error($link) . "<BR>Query: {$query}");
     //Add all columns if none was specified
     if (count($this->aCols) == 0) {
         $nb = mysqli_num_fields($res);
         for ($i = 0; $i < $nb; $i++) {
             $this->AddCol();
         }
     }
     //Retrieve column names when not specified
     foreach ($this->aCols as $i => $col) {
         if ($col['c'] == '') {
             if (is_string($col['f'])) {
                 $this->aCols[$i]['c'] = ucfirst($col['f']);
             } else {
                 $this->aCols[$i]['c'] = ucfirst(mysqli_field_name($res, $col['f']));
             }
         }
     }
     //Handle properties
     if (!isset($prop['width'])) {
         $prop['width'] = 0;
     }
     if ($prop['width'] == 0) {
         $prop['width'] = $this->w - $this->lMargin - $this->rMargin;
     }
     if (!isset($prop['align'])) {
         $prop['align'] = 'C';
     }
     if (!isset($prop['padding'])) {
         $prop['padding'] = $this->cMargin;
     }
     $cMargin = $this->cMargin;
     $this->cMargin = $prop['padding'];
     if (!isset($prop['HeaderColor'])) {
         $prop['HeaderColor'] = array();
     }
     $this->HeaderColor = $prop['HeaderColor'];
     if (!isset($prop['color1'])) {
         $prop['color1'] = array();
     }
     if (!isset($prop['color2'])) {
         $prop['color2'] = array();
     }
     $this->RowColors = array($prop['color1'], $prop['color2']);
     //Compute column widths
     $this->CalcWidths($prop['width'], $prop['align']);
     //Print header
     $this->TableHeader();
     //Print rows
     $this->SetFont('Arial', '', 11);
     $this->ColorIndex = 0;
     $this->ProcessingTable = true;
     $nameFamily = '';
     while ($row = mysqli_fetch_array($res)) {
         if ($row['nameFamily'] != $nameFamily) {
             $nameFamily = $row['nameFamily'];
             $this->Row($nameFamily);
         }
         unset($row['nameFamily']);
         $this->Row($row);
     }
     $this->ProcessingTable = false;
     $this->cMargin = $cMargin;
     $this->aCols = array();
     //return $rows;
 }
Ejemplo n.º 10
0
 function nombreCampos($sql, $pos)
 {
     $result = mysqli_query($sql);
     if ($result) {
         $nombre_campos = mysqli_field_name($result, $pos);
         mysqli_free_result($result);
         return $nombre_campos;
     } else {
         mysqli_free_result($result);
         return 0;
     }
 }
Ejemplo n.º 11
0
// Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Fetch Record from Database
$output = "";
//$table = "tbl_coronal_hole_annotations"; // Enter Your Table Name
$sql = mysqli_query($con, 'select * from tbl_coronal_hole_annotations');
if ($sql === FALSE) {
    die(mysql_error());
    // TODO: better error handling
}
$columns_total = mysqli_num_fields($sql);
// Get The Field Name
for ($i = 0; $i < $columns_total; $i++) {
    $heading = mysqli_field_name($sql, $i);
    $output .= '"' . $heading . '",';
}
$output .= "\n";
// Get Records from the table
while ($row = mysqli_fetch_array($sql)) {
    for ($i = 0; $i < $columns_total; $i++) {
        $output .= '"' . $row["{$i}"] . '",';
    }
    $output .= "\n";
}
// Download the file
$filename = "myFile.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=' . $filename);
echo $output;
Ejemplo n.º 12
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);
 }
Ejemplo n.º 13
0
 function field_exist($table, $field)
 {
     $fields = mysql_list_fields($this->database, $table);
     if ($this->mysqli) {
         $columns = mysqli_num_fields($fields);
     } else {
         $columns = mysql_num_fields($fields);
     }
     $found = 0;
     for ($i = 0; $i < $columns; $i++) {
         if ($this->mysqli) {
             if (trim($field) == trim(mysqli_field_name($fields, $i))) {
                 $found = 1;
             }
         } else {
             if (trim($field) == trim(mysql_field_name($fields, $i))) {
                 $found = 1;
             }
         }
     }
     return $found;
 }