public static function iimysqli_stmt_get_result($stmt)
 {
     /**    EXPLANATION:
      * We are creating a fake "result" structure to enable us to have
      * source-level equivalent syntax to a query executed via
      * mysqli_query().
      *
      *    $stmt = mysqli_prepare($conn, "");
      *    mysqli_bind_param($stmt, "types", ...);
      *
      *    $param1 = 0;
      *    $param2 = 'foo';
      *    $param3 = 'bar';
      *    mysqli_execute($stmt);
      *    $result _mysqli_stmt_get_result($stmt);
      *        [ $arr = _mysqli_result_fetch_array($result);
      *            || $assoc = _mysqli_result_fetch_assoc($result); ]
      *    mysqli_stmt_close($stmt);
      *    mysqli_close($conn);
      *
      * At the source level, there is no difference between this and mysqlnd.
      **/
     $metadata = mysqli_stmt_result_metadata($stmt);
     $ret = new iimysqli_result();
     if (!$ret) {
         return NULL;
     }
     $ret->nCols = mysqli_num_fields($metadata);
     $ret->columns = $metadata->fetch_fields();
     $ret->stmt = $stmt;
     mysqli_free_result($metadata);
     return $ret;
 }
Example #2
0
 /**
  * @param string $query
  * @param int $singleResult
  * @return array
  */
 function query($query, $singleResult = 0)
 {
     $this->_result = mysqli_query($this->_dbHandle, $query);
     if (preg_match("/select/i", $query)) {
         $result = array();
         $table = array();
         $field = array();
         $tempResults = array();
         $numOfFields = mysqli_num_fields($this->_result);
         while ($fdata = mysqli_fetch__field($this->_result)) {
             array_push($table, $fdata->table);
             array_push($field, $fdata->name);
         }
         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;
     }
 }
Example #3
0
function single_edit($tbl, $col, $id)
{
    $result = getSingle($tbl, $col, $id);
    $getResult = mysqli_fetch_array($result);
    echo "<form action=\"edit.php\" method=\"POST\">";
    echo "<input type=\"hidden\" name=\"tbl\" value=\"{$tbl}\">";
    echo "<input type=\"hidden\" name=\"col\" value=\"{$col}\">";
    echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\">";
    for ($i = 0; $i < mysqli_num_fields($result); $i++) {
        $dataType = mysqli_fetch_field_direct($result, $i);
        //expects two arguments
        $fieldName = $dataType->name;
        //like an associative array - allows you to dig into the object and look for "name" (seen as the label in the object with the ->)
        //$title = explode('_', $fieldName);
        $fieldType = $dataType->type;
        //returns a number that can be used
        if ($fieldName != $col) {
            echo "<label>{$fieldName}</label><br>";
            if ($fieldType != 252) {
                echo "<input type=\"text\" name=\"{$fieldName}\" value=\"{$getResult[$i]}\">";
            } else {
                echo "<textarea name=\"{$fieldName}\">{$getResult[$i]}</textarea>";
            }
        }
    }
    echo "<input type=\"submit\" value=\"Save Content\">";
    echo "</form>";
}
 /**
  * Dynamic Get Function Override
  *
  * @param $name
  *   A string containing the name of the property to get.
  * @return
  *   Value of the property.
  */
 public function __get($propertyName)
 {
     global $firePHP;
     if ($propertyName == 'columns') {
         if (!isset($this->_columns)) {
             //---- Get Columns
             $this->_columns = new anvilCollection();
             $i = 0;
             $numFields = mysqli_num_fields($this->result);
             while ($i < $numFields) {
                 //				   $meta = mysqli_fetch_field($this->result, $i);
                 $meta = mysqli_fetch_field($this->result);
                 if ($meta) {
                     //						$this->_columns->add(new anvilData_mysqli_Column($meta->name, $meta->type));
                     $firePHP->_log($meta);
                     $newColumn = new anvilData_mysqli_Column($meta->name, $meta->type);
                     $this->_columns->add($newColumn);
                 }
                 $i++;
             }
         }
         return $this->_columns;
     } else {
         return parent::__get($propertyName);
     }
 }
Example #5
0
/**
 * Fonction basée sur l'api mysqli et
 * simulant la fonction mysql_result()
 * Copyright 2014 Marc Leygnac
 *
 * @param type $result résultat après requête
 * @param integer $row numéro de la ligne
 * @param string/integer $field indice ou nom du champ
 * @return type valeur du champ ou false si erreur
 */
function old_mysql_result($result, $row, $field = 0)
{
    if ($result === false) {
        return false;
    }
    if ($row >= mysqli_num_rows($result)) {
        return false;
    }
    if (is_string($field) && !(strpos($field, ".") === false)) {
        // si $field est de la forme table.field ou alias.field
        // on convertit $field en indice numérique
        $t_field = explode(".", $field);
        $field = -1;
        $t_fields = mysqli_fetch_fields($result);
        for ($id = 0; $id < mysqli_num_fields($result); $id++) {
            if ($t_fields[$id]->table == $t_field[0] && $t_fields[$id]->name == $t_field[1]) {
                $field = $id;
                break;
            }
        }
        if ($field == -1) {
            return false;
        }
    }
    mysqli_data_seek($result, $row);
    $line = mysqli_fetch_array($result);
    return isset($line[$field]) ? $line[$field] : false;
}
 /** Custom SQL Query **/
 function query($query, $singleResult = 0)
 {
     //$query = mysqli_real_escape_string($this->_dbHandle,$query);
     //var_dump($query);
     $this->_result = mysqli_query($this->_dbHandle, $query);
     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) {
             $table_name = mysqli_fetch_field_direct($this->_result, $i);
             array_push($table, $table_name->table);
             $fld = mysqli_fetch_field_direct($this->_result, $i);
             array_push($field, $fld->name);
         }
         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;
     }
 }
Example #7
0
 public function getNumFields()
 {
     if ($this->usemysqli) {
         return mysqli_num_fields($this->result);
     } else {
         return mysql_numfields($this->result);
     }
 }
 function num_fields($res)
 {
     if ($num = mysqli_num_fields($res)) {
         return $num;
     } else {
         return false;
     }
 }
Example #9
0
 /**
  * Extracts data from database table (for MySQLi driver)
  *
  * @param	string	$table_name	name of the database table
  * @return null
  * @throws \phpbb\db\extractor\exception\extractor_not_initialized_exception when calling this function before init_extractor()
  */
 protected function write_data_mysqli($table_name)
 {
     if (!$this->is_initialized) {
         throw new extractor_not_initialized_exception();
     }
     $sql = "SELECT *\n\t\t\tFROM {$table_name}";
     $result = mysqli_query($this->db->get_db_connect_id(), $sql, MYSQLI_USE_RESULT);
     if ($result != false) {
         $fields_cnt = mysqli_num_fields($result);
         // Get field information
         $field = mysqli_fetch_fields($result);
         $field_set = array();
         for ($j = 0; $j < $fields_cnt; $j++) {
             $field_set[] = $field[$j]->name;
         }
         $search = array("\\", "'", "", "\n", "\r", "", '"');
         $replace = array("\\\\", "\\'", '\\0', '\\n', '\\r', '\\Z', '\\"');
         $fields = implode(', ', $field_set);
         $sql_data = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES ';
         $first_set = true;
         $query_len = 0;
         $max_len = get_usable_memory();
         while ($row = mysqli_fetch_row($result)) {
             $values = array();
             if ($first_set) {
                 $query = $sql_data . '(';
             } else {
                 $query .= ',(';
             }
             for ($j = 0; $j < $fields_cnt; $j++) {
                 if (!isset($row[$j]) || is_null($row[$j])) {
                     $values[$j] = 'NULL';
                 } else {
                     if ($field[$j]->flags & 32768 && !($field[$j]->flags & 1024)) {
                         $values[$j] = $row[$j];
                     } else {
                         $values[$j] = "'" . str_replace($search, $replace, $row[$j]) . "'";
                     }
                 }
             }
             $query .= implode(', ', $values) . ')';
             $query_len += strlen($query);
             if ($query_len > $max_len) {
                 $this->flush($query . ";\n\n");
                 $query = '';
                 $query_len = 0;
                 $first_set = true;
             } else {
                 $first_set = false;
             }
         }
         mysqli_free_result($result);
         // check to make sure we have nothing left to flush
         if (!$first_set && $query) {
             $this->flush($query . ";\n\n");
         }
     }
 }
Example #10
0
function db_num_fields($res)
{
    switch (DATABASE) {
        case 'mysql':
            return mysql_num_fields($res);
        case 'mysqli':
            return mysqli_num_fields($res);
    }
}
 function _getFieldCount()
 {
     if (is_object($this->_cursor) && get_class($this->_cursor) == "mysqli_result") {
         $fields = mysqli_num_fields($this->_cursor);
         return $fields;
     }
     // This is either a broken db connection or a bad query
     return 0;
 }
Example #12
0
 public static function backup($tables = '*')
 {
     ini_set('memory_limit', '2048M');
     set_time_limit(0);
     $folder = dirname(__FILE__) . "/../backup";
     $file = 'backup' . date("Ymd");
     if (!file_exists("{$folder}/{$file}")) {
         echo "creando {$folder}/{$file}";
         $old_mask = umask(0);
         mkdir("{$folder}/{$file}", 0757);
         umask($old_mask);
     }
     if ($tables == '*') {
         $tables = array();
         $result = self::consultar('SHOW TABLES FROM Proyecto');
         while ($row = mysqli_fetch_row($result)) {
             $tables[] = $row[0];
         }
     } else {
         $tables = is_array($tables) ? $tables : explode(',', $tables);
     }
     foreach ($tables as $table) {
         $return = '';
         $result = self::consultar('SELECT * FROM ' . $table);
         $num_fields = mysqli_num_fields($result);
         $row2 = mysqli_fetch_row(self::consultar('SHOW CREATE TABLE ' . $table));
         $return .= "\n\n" . $row2[1] . ";\n\n";
         for ($i = 0; $i < $num_fields; $i++) {
             while ($row = mysqli_fetch_row($result)) {
                 $return .= 'INSERT INTO ' . $table . ' VALUES(';
                 for ($j = 0; $j < $num_fields; $j++) {
                     $row[$j] = addslashes($row[$j]);
                     $row[$j] = preg_replace("/\n/", "\\n", $row[$j]);
                     if (isset($row[$j])) {
                         $return .= '"' . $row[$j] . '"';
                     } else {
                         $return .= '""';
                     }
                     if ($j < $num_fields - 1) {
                         $return .= ',';
                     }
                 }
                 $return .= ");\n";
             }
         }
         $return .= "\n\n\n";
         //save file
         $handle = fopen("{$folder}/{$file}/{$table}.sql", 'w+');
         if (fwrite($handle, $return)) {
             echo "Tabla: {$table} guardada correctamente en {$folder}/{$table}.sql.";
         } else {
             echo "No se pudo hacer la copia para la tabla {$table}";
         }
     }
     fclose($handle);
     return $file;
 }
Example #13
0
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function mysqliAdapter($d)
 {
     parent::RecordSetAdapter($d);
     $fieldcount = mysqli_num_fields($d);
     $ob = "";
     $be = $this->isBigEndian;
     $fc = pack('N', $fieldcount);
     if (mysqli_num_rows($d) > 0) {
         mysqli_data_seek($d, 0);
         while ($line = mysqli_fetch_row($d)) {
             // write all of the array elements
             $ob .= "\n" . $fc;
             foreach ($line as $value) {
                 // write all of the array elements
                 if (is_string($value)) {
                     // type as string
                     $os = $this->_directCharsetHandler->transliterate($value);
                     //string flag, string length, and string
                     $len = strlen($os);
                     if ($len < 65536) {
                         $ob .= "" . pack('n', $len) . $os;
                     } else {
                         $ob .= "\f" . pack('N', $len) . $os;
                     }
                 } elseif (is_float($value) || is_int($value)) {
                     // type as double
                     $b = pack('d', $value);
                     // pack the bytes
                     if ($be) {
                         // if we are a big-endian processor
                         $r = strrev($b);
                     } else {
                         // add the bytes to the output
                         $r = $b;
                     }
                     $ob .= "" . $r;
                 } elseif (is_bool($value)) {
                     //type as bool
                     $ob .= "";
                     $ob .= pack('c', $value);
                 } elseif (is_null($value)) {
                     // null
                     $ob .= "";
                 }
             }
         }
     }
     $this->serializedData = $ob;
     // loop over all of the fields
     while ($field = mysqli_fetch_field($d)) {
         // decode each field name ready for encoding when it goes through serialization
         // and save each field name into the array
         $this->columnNames[] = $this->_directCharsetHandler->transliterate($field->name);
     }
     $this->numRows = mysqli_num_rows($d);
 }
Example #14
0
function dumpMySQL()
{
    global $dbc;
    $connexion = $dbc;
    $entete = "-- ----------------------\n";
    $entete .= "-- dump de la base " . $base . " au " . date("d-M-Y") . "\n";
    $entete .= "-- ----------------------\n\n\n";
    $creations = "";
    $insertions = "\n\n";
    $listeTables = mysqli_query($connexion, "show tables");
    while ($table = mysqli_fetch_array($listeTables)) {
        // si l'utilisateur a demande la structure ou la totale
        //if ( $table[0] == "cahiertxt" || $table[0] == "onglets" )
        if (mb_ereg("^cahiertxt", $table[0]) || mb_ereg("^onglets", $table[0])) {
            $creations .= "-- -----------------------------\n";
            $creations .= "-- creation de la table " . $table[0] . "\n";
            $creations .= "-- -----------------------------\n";
            $creations .= "DROP TABLE IF EXISTS `" . $table[0] . "`;\n";
            $listeCreationsTables = mysqli_query($connexion, "show create table " . $table[0]);
            while ($creationTable = mysqli_fetch_array($listeCreationsTables)) {
                $creations .= $creationTable[1] . ";\n\n";
            }
            //donnees
            $donnees = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM " . $table[0] . "  WHERE login='******'login'] . "'");
            $insertions .= "-- -----------------------------\n";
            $insertions .= "-- insertions dans la table " . $table[0] . "\n";
            $insertions .= "-- -----------------------------\n";
            while ($nuplet = mysqli_fetch_array($donnees)) {
                $insertions .= "INSERT INTO " . $table[0] . " VALUES(";
                for ($i = 0; $i < (($___mysqli_tmp = mysqli_num_fields($donnees)) ? $___mysqli_tmp : false); $i++) {
                    if ($i != 0) {
                        $insertions .= ", ";
                    }
                    if ((is_object($___mysqli_tmp = mysqli_fetch_field_direct($donnees, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type) ? ($___mysqli_tmp = (string) substr(($___mysqli_tmp == MYSQLI_TYPE_STRING || $___mysqli_tmp == MYSQLI_TYPE_VAR_STRING ? "string " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24)) ? "int " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, defined("MYSQLI_TYPE_NEWDECIMAL") ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)) ? "real " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP ? "timestamp " : "") . ($___mysqli_tmp == MYSQLI_TYPE_YEAR ? "year " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATE || $___mysqli_tmp == MYSQLI_TYPE_NEWDATE ? "date " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIME ? "time " : "") . ($___mysqli_tmp == MYSQLI_TYPE_SET ? "set " : "") . ($___mysqli_tmp == MYSQLI_TYPE_ENUM ? "enum " : "") . ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY ? "geometry " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATETIME ? "datetime " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)) ? "blob " : "") . ($___mysqli_tmp == MYSQLI_TYPE_NULL ? "null " : ""), 0, -1)) == "" ? "unknown" : $___mysqli_tmp : false) == "string" || (is_object($___mysqli_tmp = mysqli_fetch_field_direct($donnees, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type) ? ($___mysqli_tmp = (string) substr(($___mysqli_tmp == MYSQLI_TYPE_STRING || $___mysqli_tmp == MYSQLI_TYPE_VAR_STRING ? "string " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24)) ? "int " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, defined("MYSQLI_TYPE_NEWDECIMAL") ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)) ? "real " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP ? "timestamp " : "") . ($___mysqli_tmp == MYSQLI_TYPE_YEAR ? "year " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATE || $___mysqli_tmp == MYSQLI_TYPE_NEWDATE ? "date " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIME ? "time " : "") . ($___mysqli_tmp == MYSQLI_TYPE_SET ? "set " : "") . ($___mysqli_tmp == MYSQLI_TYPE_ENUM ? "enum " : "") . ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY ? "geometry " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATETIME ? "datetime " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)) ? "blob " : "") . ($___mysqli_tmp == MYSQLI_TYPE_NULL ? "null " : ""), 0, -1)) == "" ? "unknown" : $___mysqli_tmp : false) == "blob" || (is_object($___mysqli_tmp = mysqli_fetch_field_direct($donnees, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type) ? ($___mysqli_tmp = (string) substr(($___mysqli_tmp == MYSQLI_TYPE_STRING || $___mysqli_tmp == MYSQLI_TYPE_VAR_STRING ? "string " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24)) ? "int " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, defined("MYSQLI_TYPE_NEWDECIMAL") ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)) ? "real " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP ? "timestamp " : "") . ($___mysqli_tmp == MYSQLI_TYPE_YEAR ? "year " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATE || $___mysqli_tmp == MYSQLI_TYPE_NEWDATE ? "date " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIME ? "time " : "") . ($___mysqli_tmp == MYSQLI_TYPE_SET ? "set " : "") . ($___mysqli_tmp == MYSQLI_TYPE_ENUM ? "enum " : "") . ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY ? "geometry " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATETIME ? "datetime " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)) ? "blob " : "") . ($___mysqli_tmp == MYSQLI_TYPE_NULL ? "null " : ""), 0, -1)) == "" ? "unknown" : $___mysqli_tmp : false) == "timestamp" || (is_object($___mysqli_tmp = mysqli_fetch_field_direct($donnees, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type) ? ($___mysqli_tmp = (string) substr(($___mysqli_tmp == MYSQLI_TYPE_STRING || $___mysqli_tmp == MYSQLI_TYPE_VAR_STRING ? "string " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24)) ? "int " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, defined("MYSQLI_TYPE_NEWDECIMAL") ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)) ? "real " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP ? "timestamp " : "") . ($___mysqli_tmp == MYSQLI_TYPE_YEAR ? "year " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATE || $___mysqli_tmp == MYSQLI_TYPE_NEWDATE ? "date " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIME ? "time " : "") . ($___mysqli_tmp == MYSQLI_TYPE_SET ? "set " : "") . ($___mysqli_tmp == MYSQLI_TYPE_ENUM ? "enum " : "") . ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY ? "geometry " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATETIME ? "datetime " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)) ? "blob " : "") . ($___mysqli_tmp == MYSQLI_TYPE_NULL ? "null " : ""), 0, -1)) == "" ? "unknown" : $___mysqli_tmp : false) == "date") {
                        $insertions .= "'";
                    }
                    $insertions .= addslashes($nuplet[$i]);
                    if ((is_object($___mysqli_tmp = mysqli_fetch_field_direct($donnees, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type) ? ($___mysqli_tmp = (string) substr(($___mysqli_tmp == MYSQLI_TYPE_STRING || $___mysqli_tmp == MYSQLI_TYPE_VAR_STRING ? "string " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24)) ? "int " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, defined("MYSQLI_TYPE_NEWDECIMAL") ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)) ? "real " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP ? "timestamp " : "") . ($___mysqli_tmp == MYSQLI_TYPE_YEAR ? "year " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATE || $___mysqli_tmp == MYSQLI_TYPE_NEWDATE ? "date " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIME ? "time " : "") . ($___mysqli_tmp == MYSQLI_TYPE_SET ? "set " : "") . ($___mysqli_tmp == MYSQLI_TYPE_ENUM ? "enum " : "") . ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY ? "geometry " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATETIME ? "datetime " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)) ? "blob " : "") . ($___mysqli_tmp == MYSQLI_TYPE_NULL ? "null " : ""), 0, -1)) == "" ? "unknown" : $___mysqli_tmp : false) == "string" || (is_object($___mysqli_tmp = mysqli_fetch_field_direct($donnees, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type) ? ($___mysqli_tmp = (string) substr(($___mysqli_tmp == MYSQLI_TYPE_STRING || $___mysqli_tmp == MYSQLI_TYPE_VAR_STRING ? "string " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24)) ? "int " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, defined("MYSQLI_TYPE_NEWDECIMAL") ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)) ? "real " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP ? "timestamp " : "") . ($___mysqli_tmp == MYSQLI_TYPE_YEAR ? "year " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATE || $___mysqli_tmp == MYSQLI_TYPE_NEWDATE ? "date " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIME ? "time " : "") . ($___mysqli_tmp == MYSQLI_TYPE_SET ? "set " : "") . ($___mysqli_tmp == MYSQLI_TYPE_ENUM ? "enum " : "") . ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY ? "geometry " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATETIME ? "datetime " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)) ? "blob " : "") . ($___mysqli_tmp == MYSQLI_TYPE_NULL ? "null " : ""), 0, -1)) == "" ? "unknown" : $___mysqli_tmp : false) == "blob" || (is_object($___mysqli_tmp = mysqli_fetch_field_direct($donnees, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type) ? ($___mysqli_tmp = (string) substr(($___mysqli_tmp == MYSQLI_TYPE_STRING || $___mysqli_tmp == MYSQLI_TYPE_VAR_STRING ? "string " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24)) ? "int " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, defined("MYSQLI_TYPE_NEWDECIMAL") ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)) ? "real " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP ? "timestamp " : "") . ($___mysqli_tmp == MYSQLI_TYPE_YEAR ? "year " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATE || $___mysqli_tmp == MYSQLI_TYPE_NEWDATE ? "date " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIME ? "time " : "") . ($___mysqli_tmp == MYSQLI_TYPE_SET ? "set " : "") . ($___mysqli_tmp == MYSQLI_TYPE_ENUM ? "enum " : "") . ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY ? "geometry " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATETIME ? "datetime " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)) ? "blob " : "") . ($___mysqli_tmp == MYSQLI_TYPE_NULL ? "null " : ""), 0, -1)) == "" ? "unknown" : $___mysqli_tmp : false) == "timestamp" || (is_object($___mysqli_tmp = mysqli_fetch_field_direct($donnees, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type) ? ($___mysqli_tmp = (string) substr(($___mysqli_tmp == MYSQLI_TYPE_STRING || $___mysqli_tmp == MYSQLI_TYPE_VAR_STRING ? "string " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24)) ? "int " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, defined("MYSQLI_TYPE_NEWDECIMAL") ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)) ? "real " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP ? "timestamp " : "") . ($___mysqli_tmp == MYSQLI_TYPE_YEAR ? "year " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATE || $___mysqli_tmp == MYSQLI_TYPE_NEWDATE ? "date " : "") . ($___mysqli_tmp == MYSQLI_TYPE_TIME ? "time " : "") . ($___mysqli_tmp == MYSQLI_TYPE_SET ? "set " : "") . ($___mysqli_tmp == MYSQLI_TYPE_ENUM ? "enum " : "") . ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY ? "geometry " : "") . ($___mysqli_tmp == MYSQLI_TYPE_DATETIME ? "datetime " : "") . (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)) ? "blob " : "") . ($___mysqli_tmp == MYSQLI_TYPE_NULL ? "null " : ""), 0, -1)) == "" ? "unknown" : $___mysqli_tmp : false) == "date") {
                        $insertions .= "'";
                    }
                }
                $insertions .= ");\n";
            }
            $insertions .= "\n";
        }
    }
    is_null($___mysqli_res = mysqli_close($connexion)) ? false : $___mysqli_res;
    $rep_tmp = "/tmp/" . $_SESSION['login'];
    mkdir($rep_tmp);
    $fichierDump = fopen($rep_tmp . "/dump.sql", "wb");
    fwrite($fichierDump, $entete);
    fwrite($fichierDump, $creations);
    fwrite($fichierDump, $insertions);
    fclose($fichierDump);
}
Example #15
0
 function backup_tables($host, $user, $pass, $name, $tables = '*')
 {
     //name is db name
     $link = mysqli_connect($host, $user, $pass, $name);
     //mysql_select_db($name, $link);
     mysqli_query($link, "SET NAMES 'utf8'");
     //get all of the tables
     if ($tables == '*') {
         $tables = array();
         $result = mysqli_query($link, 'SHOW TABLES');
         while ($row = mysqli_fetch_row($result)) {
             $tables[] = $row[0];
         }
     } else {
         $tables = is_array($tables) ? $tables : explode(',', $tables);
     }
     $return = '';
     //cycle through
     foreach ($tables as $table) {
         $result = mysqli_query($link, 'SELECT * FROM ' . $table);
         $num_fields = mysqli_num_fields($result);
         $return .= 'DROP TABLE ' . $table . ';';
         $row2 = mysqli_fetch_row(mysqli_query($link, 'SHOW CREATE TABLE ' . $table));
         $return .= "\n\n" . $row2[1] . ";\n\n";
         for ($i = 0; $i < $num_fields; $i++) {
             while ($row = mysqli_fetch_row($result)) {
                 $return .= 'INSERT INTO ' . $table . ' VALUES(';
                 for ($j = 0; $j < $num_fields; $j++) {
                     $row[$j] = addslashes($row[$j]);
                     $row[$j] = str_replace("\n", "\\n", $row[$j]);
                     if (isset($row[$j])) {
                         $return .= '"' . $row[$j] . '"';
                     } else {
                         $return .= '""';
                     }
                     if ($j < $num_fields - 1) {
                         $return .= ',';
                     }
                 }
                 $return .= ");\n";
             }
         }
         $return .= "\n\n\n";
     }
     //save file
     $fileName = 'db-backup-' . date('d-m-Y') . '.sql';
     $handle = fopen(storage_path('app/' . $fileName), 'w+');
     fwrite($handle, $return);
     fclose($handle);
     $this->emailDatabase($fileName);
     if ($this->deleteBackupFile) {
         unlink(storage_path('app/' . $fileName));
     }
 }
Example #16
0
 public static function makeMysqldump($type = 'text')
 {
     //connect with database
     $obj_db = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAAM);
     if ($obj_db === FALSE) {
         $error = "Database connection failed";
         printf("Connect failed: %s\n", mysqli_connect_error());
         exit;
     }
     $tables = array();
     $result = mysqli_query($obj_db, 'SHOW TABLES');
     while ($row = mysqli_fetch_row($result)) {
         $tables[] = $row[0];
     }
     $return = '';
     //cycle through
     foreach ($tables as $table) {
         $result = mysqli_query($obj_db, 'SELECT * FROM ' . $table);
         $num_fields = mysqli_num_fields($result);
         $arr_create_table = mysqli_fetch_row(mysqli_query($obj_db, 'SHOW CREATE TABLE ' . $table));
         $str_create_table = "\n\n" . $arr_create_table[1] . ";\n\n";
         $return .= str_replace('CREATE TABLE `' . $table . '` (', 'CREATE TABLE IF NOT EXISTS `' . $table . '` (', $str_create_table);
         for ($i = 0; $i < $num_fields; $i++) {
             while ($row = mysqli_fetch_row($result)) {
                 $return .= 'INSERT INTO `' . $table . '` VALUES(';
                 for ($j = 0; $j < $num_fields; $j++) {
                     $row[$j] = addslashes($row[$j]);
                     $row[$j] = str_replace("\n", "\\n", $row[$j]);
                     if (isset($row[$j])) {
                         $return .= '"' . $row[$j] . '"';
                     } else {
                         $return .= '""';
                     }
                     if ($j < $num_fields - 1) {
                         $return .= ',';
                     }
                 }
                 $return .= ");\n";
             }
         }
         $return .= "\n\n\n";
     }
     $int_result = file_put_contents(FULLCAL_DIR . '/system/dbdump/caldump_' . date("Y-m-d_H-i") . '.txt', $return);
     if ($int_result > 0) {
         // met bijgewerkte datum in schedule tabel zetten
         $str_query = 'REPLACE INTO `schedule` SET `jobname` = "sqldump" , `last_exec_date` = NOW() ';
         global $obj_db;
         $obj_result = mysqli_query($obj_db, $str_query);
         if ($obj_result !== false) {
             return true;
         }
     }
     return false;
 }
Example #17
0
 function sql_numfields($query_id = 0)
 {
     if (!$query_id) {
         $query_id = $this->query_result;
     }
     if ($query_id) {
         $result = @mysqli_num_fields($query_id);
         return $result;
     } else {
         return false;
     }
 }
Example #18
0
 /**
  * @param $data - mysqli result
  * @param $title - true / false (show or not the title)
  * @return string
  */
 public function query_output($data)
 {
     if (!$data) {
         $table_output = 'No data to display, quitting.<br>';
         return 'error in htmloutput.php library class: query argument required';
     }
     //$table_output = 'Data was passed to query_output method.<br>';
     // $table_output = $table_output.'------------------------------------------------------------------------------------------------------------------------------------<br>';
     // display columns field names
     $i = 0;
     $table_output = '<html><body><table><tr>';
     while ($i < mysqli_num_fields($data)) {
         $meta = mysqli_fetch_field($data);
         if ($title == 'true') {
             $table_output = $table_output . '<td>' . $meta->name . '</td>';
         }
         $i = $i + 1;
     }
     $table_output = $table_output . '</tr>';
     // SHOULD Display only the selected range, thus making 'pages'.
     //$i     = $range['first_row'];
     //$count = $range['last_row'];
     // echo "from htmloutput.php: from ".$range['first_row']." to ".$range['last_row']." rows.<br>";
     //mysqli_data_seek($data, $range['first_row']);
     //if ($range['last_row'] !== -1 ) {
     //    $last_row = $range['last_row'];
     //} else {
     //    $last_row = mysqli_num_rows ($data);
     //}
     //$r = $range['first_row'];
     $r = 0;
     $last_row = mysqli_num_rows($data);
     while ($r < $last_row) {
         $row = mysqli_fetch_row($data);
         $table_output .= '<tr>';
         $count = count($row);
         $y = 0;
         //columns
         while ($y < $count) {
             $c_row = current($row);
             $table_output .= '<td>' . $c_row . '</td>';
             next($row);
             $y = $y + 1;
             // walk the columns one by one
         }
         $table_output .= '</tr>';
         $r = $r + 1;
     }
     echo '</table></body></html>';
     return $table_output;
 }
Example #19
0
function SelectValues($result)
{
    if (@mysqli_num_rows($result) == 0) {
        echo "<option selected disabled>Nenhum item encontrado</option>";
    } else {
        echo "<option selected disabled>Selecione...</option>";
        for ($i = 0; $i < mysqli_num_rows($result); $i++) {
            for ($j = 0; $j < mysqli_num_fields($result); $j++) {
                $valor = mysqli_fetch_row($result)[$j];
                echo "<option value=" . $valor . ">" . $valor . "</option>";
            }
        }
    }
}
Example #20
0
function num_fields($query_id = 0)
{
    global $db_type;
    if (!$query_id) {
        $query_id = $this->query_result;
    }
    switch ($db_type) {
        case 'mysql':
            return $query_id ? @mysql_num_fields($query_id) : false;
            break;
        case 'mysqli':
            return $query_id ? @mysqli_num_fields($query_id) : false;
    }
}
Example #21
0
function func_test_mysqli_num_fields($link, $query, $expected, $offset, $test_free = false)
{
    if (!($res = mysqli_query($link, $query))) {
        printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return;
    }
    if ($expected !== ($tmp = mysqli_num_fields($res))) {
        printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1, gettype($expected), $expected, gettype($tmp), $tmp);
    }
    mysqli_free_result($res);
    if ($test_free && NULL !== ($tmp = mysqli_num_fields($res))) {
        printf("[%03d] Expecting NULL, got %s/%s\n", $offset + 2, gettype($tmp), $tmp);
    }
}
Example #22
0
 function backup_tables($con, $tables = 'film')
 {
     //  $link = mysql_connect($host,$user,$pass);
     //  mysql_select_db($name,$link);
     //get all of the tables
     if ($tables == '*') {
         $tables = array();
         $result = mysqli_query($con, 'SHOW TABLES');
         while ($row = mysqli_fetch_row($result, MYSQLI_NUM)) {
             $tables[] = $row[0];
         }
     } else {
         $tables = is_array($tables) ? $tables : explode(',', $tables);
     }
     //cycle through
     foreach ($tables as $table) {
         $result = mysqli_query($con, 'SELECT * FROM ' . $table);
         $num_fields = mysqli_num_fields($result);
         @($return .= 'DROP TABLE IF EXISTS ' . $table . ';');
         $row2 = mysqli_fetch_row(mysqli_query($con, 'SHOW CREATE TABLE ' . $table));
         $return .= "\n\n" . $row2[1] . ";\n\n";
         for ($i = 0; $i < $num_fields; $i++) {
             while ($row = mysqli_fetch_row($result)) {
                 $return .= 'INSERT INTO ' . $table . ' VALUES(';
                 for ($j = 0; $j < $num_fields; $j++) {
                     $row[$j] = addslashes($row[$j]);
                     $row[$j] = preg_replace("#\n#", "\\n", $row[$j]);
                     if (isset($row[$j])) {
                         $return .= '"' . $row[$j] . '"';
                     } else {
                         $return .= '""';
                     }
                     if ($j < $num_fields - 1) {
                         $return .= ',';
                     }
                 }
                 $return .= ");\n";
             }
         }
         $return .= "\n\n\n";
     }
     //save file
     //$handle = fopen('rvg-db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
     //fwrite($handle,$return);
     //fclose($handle);
     $filename = 'film_table' . '.sql';
     Header("Content-type: application/octet-stream");
     Header("Content-Disposition: attachment; filename={$filename}");
     echo $return;
 }
Example #23
0
 public function __construct($qvar)
 {
     //constructor takes query string as a parameter
     include "/home/ubuntu/workspace/db_connect.php";
     //contains $conn - Oracle connection info
     $this->qvar = $qvar;
     $sql = $mysqli->query($this->qvar);
     $this->numcols = mysqli_num_fields($sql);
     $this->colname = mysqli_fetch_fields($sql);
     $this->numrows = mysqli_num_rows($sql);
     while ($row = mysqli_fetch_assoc($sql)) {
         $this->tableArray[] = $row;
     }
     $sql->close();
 }
Example #24
0
 /**
  * TODO: replace the $link stuff by usage of $GLOBALS['TYPO3_DB']
  *
  * @param string $outputFolder
  * @return string
  */
 public static function backupTable($outputFolder)
 {
     GeneralUtility::mkdir_deep($outputFolder);
     $host = $GLOBALS['TYPO3_CONF_VARS']['DB']['host'];
     $user = $GLOBALS['TYPO3_CONF_VARS']['DB']['username'];
     $pass = $GLOBALS['TYPO3_CONF_VARS']['DB']['password'];
     $name = $GLOBALS['TYPO3_CONF_VARS']['DB']['database'];
     $link = mysqli_connect($host, $user, $pass);
     mysqli_select_db($link, $name);
     $listDbTables = array_column(mysqli_fetch_all($link->query('SHOW TABLES')), 0);
     $listDbTables = self::removeCacheAndLogTables($listDbTables);
     $return = '';
     foreach ($listDbTables as $table) {
         $result = mysqli_query($link, 'SELECT * FROM ' . $table);
         $numFields = mysqli_num_fields($result);
         $return .= 'DROP TABLE ' . $table . ';';
         $row2 = mysqli_fetch_row(mysqli_query($link, 'SHOW CREATE TABLE ' . $table));
         $return .= "\n\n" . $row2[1] . ";\n\n";
         for ($i = 0; $i < $numFields; $i++) {
             while ($row = mysqli_fetch_row($result)) {
                 $return .= 'INSERT INTO ' . $table . ' VALUES(';
                 for ($j = 0; $j < $numFields; $j++) {
                     $row[$j] = addslashes($row[$j]);
                     $row[$j] = str_replace("\n", "\\n", $row[$j]);
                     if (isset($row[$j])) {
                         $return .= '"' . $row[$j] . '"';
                     } else {
                         $return .= '""';
                     }
                     if ($j < $numFields - 1) {
                         $return .= ',';
                     }
                 }
                 $return .= ");\n";
             }
         }
         $return .= "\n\n\n";
     }
     //save file
     $backupFileName = 'db-backup_' . time() . '.sql';
     $handle = fopen($outputFolder . $backupFileName, 'w+');
     fwrite($handle, $return);
     fclose($handle);
     self::generateBackupLog($name, $backupFileName . '.gz', $outputFolder, 3);
     return self::gzCompressFile($outputFolder . 'db-backup_' . time() . '.sql');
 }
Example #25
0
function read($tabela, $cond = null)
{
    $con = mysqli_connect(HOST, USER, PASS, DBAS) or die(mysqli_error($con) . "Não foi possível fazer a conexão com o sistema");
    $qrRead = "SELECT * FROM {$tabela} {$cond}";
    $stRead = mysqli_query($con, $qrRead);
    $cFields = mysqli_num_fields($stRead);
    for ($y = 0; $y < $cFields; $y++) {
        $n = mysqli_fetch_field($stRead);
        $names[$y] = $n->name;
    }
    for ($x = 0; $x < ($res = mysqli_fetch_assoc($stRead)); $x++) {
        for ($i = 0; $i < $cFields; $i++) {
            $resultado[$x][$names[$i]] = $res[$names[$i]];
        }
    }
    return $resultado;
    mysqli_close($con);
}
Example #26
0
 /**
  * Parse resource into array
  *
  * @param resource $resource
  * @return array
  */
 public function parse($resource)
 {
     $result = array();
     $fieldcnt = mysqli_num_fields($resource);
     $fields_transform = array();
     for ($i = 0; $i < $fieldcnt; $i++) {
         $finfo = mysqli_fetch_field_direct($resource, $i);
         if (isset(self::$mysqli_type[$finfo->type])) {
             $fields_transform[$finfo->name] = self::$mysqli_to_php[self::$mysqli_type[$finfo->type]];
         }
     }
     while ($row = mysqli_fetch_assoc($resource)) {
         foreach ($fields_transform as $fieldname => $fieldtype) {
             settype($row[$fieldname], $fieldtype);
         }
         $result[] = $row;
     }
     return $result;
 }
Example #27
0
function mostrarPersonas($conexion)
{
    echo 'Entrando a la BBDD <br />';
    // Almacenamos la consulta.
    $query = 'SELECT * FROM persona;';
    // Almacenamos la consulta en un Array de Resultado con fetch_row.
    $resultado = mysqli_query($conexion, $query);
    $longitud = mysqli_num_fields($resultado);
    // Vamos mostrando fila por fila los resultados.
    while ($fila = mysqli_fetch_row($resultado)) {
        //echo $fila[0];
        // Imprimimmos según la longitud gracias a fecth_lengths
        for ($i = 0; $i < $longitud; $i++) {
            echo $fila[$i] . ' - ';
        }
        echo '<br />';
    }
    mysqli_close($conexion);
}
function tableRowBuilder($sql, $conn)
{
    //ex: '"hostname","username","password","database"';
    $conn = '"nallware.db.8715276.hostedresource.com","nallware","Nall#5440","nallware"';
    $con = mysqli_connect($conn);
    if (mysqli_connect_errno()) {
        return "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysqli_query($con, $sql);
    while ($row = mysqli_fetch_array($result)) {
        $col_cnt = mysqli_num_fields($result);
        $tablerow = "<tr>";
        for ($x = 0; $x <= $col_cnt; $x++) {
            $tablerow .= "<td>" . $row[$x] . "</td>";
        }
        $tablerow .= "</tr>";
    }
    mysqli_close($con);
    return $tablerow;
}
Example #29
0
function TableShow($result)
{
    echo "<table>";
    echo "<tr>";
    // print headers
    for ($i = 0; $i < mysqli_num_fields($result); $i++) {
        $field_info = mysqli_fetch_field_direct($result, $i);
        echo "<th>{$field_info->name}</th>";
    }
    echo "</tr>";
    // print data
    while ($tableRow = mysqli_fetch_assoc($result)) {
        echo "<tr>";
        foreach ($tableRow as $key => $value) {
            echo "<td>" . $tableRow[$key] . "</td>";
            //echo $key;
        }
        echo "</tr>";
    }
    echo "</table>";
}
Example #30
0
 function backup_tables($tables = '*')
 {
     //get all of the tables
     $tables = array();
     $result = mysqli_query($this->con, 'SHOW TABLES');
     while ($row = mysqli_fetch_row($result)) {
         $tables[] = $row[0];
     }
     $return = "";
     //cycle through
     foreach ($tables as $table) {
         $result = mysqli_query($this->con, 'SELECT * FROM ' . $table);
         $num_fields = mysqli_num_fields($result);
         $return .= 'DROP TABLE ' . $table . ';';
         $row2 = mysqli_fetch_row(mysqli_query($this->con, 'SHOW CREATE TABLE ' . $table));
         $return .= "\n\n" . $row2[1] . ";\n\n";
         while ($row = mysqli_fetch_row($result)) {
             $return .= 'INSERT INTO ' . $table . ' VALUES(';
             for ($j = 0; $j < $num_fields; $j++) {
                 $row[$j] = addslashes($row[$j]);
                 $row[$j] = preg_replace("#\n#", "\\n", $row[$j]);
                 if (isset($row[$j])) {
                     $return .= '"' . $row[$j] . '"';
                 } else {
                     $return .= '""';
                 }
                 if ($j < $num_fields - 1) {
                     $return .= ',';
                 }
             }
             $return .= ");\n";
         }
         $return .= "\n\n\n";
     }
     //save file
     $handle = fopen('db-backup-dreamsoft-' . time() . '-' . md5(implode(',', $tables)) . '.sql', 'w+');
     fwrite($handle, $return);
     fclose($handle);
 }