Exemple #1
0
 function get_table_fields($table)
 {
     $result = $this->select_from_table($table);
     $i = 0;
     $fields = array();
     while ($i < mysql_num_fields($result)) {
         $fields[$i] = mysql_fetch_field($result, $i);
         /*
             PROPERTIES
             $field->blob
             $field->max_length
             $field->multiple_key
             $field->name
             $field->not_null
             $field->numeric
             $field->primary_key
             $field->table
             $field->type
             $field->def
             $field->unique_key
             $field->unsigned
             $field->zerofill
         */
         $i++;
     }
     return $fields;
 }
Exemple #2
0
 function readfield()
 {
     $this->error = '';
     $result = @mysql_fetch_field($this->result);
     $this->catcherror();
     return $result;
 }
Exemple #3
0
function mysql2json($mysql_result, $name)
{
    $json = "{\n\"{$name}\": [\n";
    $field_names = array();
    $fields = mysql_num_fields($mysql_result);
    for ($x = 0; $x < $fields; $x++) {
        $field_name = mysql_fetch_field($mysql_result, $x);
        if ($field_name) {
            $field_names[$x] = $field_name->name;
        }
    }
    $rows = mysql_num_rows($mysql_result);
    for ($x = 0; $x < $rows; $x++) {
        $row = str_replace('"', '\\"', mysql_fetch_array($mysql_result));
        $json .= "{\n";
        for ($y = 0; $y < count($field_names); $y++) {
            $json .= "\"{$field_names[$y]}\" :\t\"{$row[$y]}\"";
            if ($y == count($field_names) - 1) {
                $json .= "\n";
            } else {
                $json .= ",\n";
            }
        }
        if ($x == $rows - 1) {
            $json .= "\n}\n";
        } else {
            $json .= "\n},\n";
        }
    }
    $json .= "]\n};";
    return $json;
}
function returnValues($sql_result)
{
    $x = 0;
    $controlNumber = 0;
    global $field;
    global $return;
    if (mysql_num_rows($sql_result) > 0) {
        $return = true;
        while ($fieldName = mysql_fetch_field($sql_result)) {
            $name[$x] = $fieldName->name;
            $x++;
            $controlNumber++;
        }
        $x = 0;
        while ($row = mysql_fetch_assoc($sql_result)) {
            while ($controlNumber > 0) {
                $field[$name[$x]] = $row[$name[$x]];
                //echo $name[$x].": ".$field[$name[$x]]."<br> ";
                $x++;
                $controlNumber--;
            }
        }
    } else {
        $return = false;
    }
}
Exemple #5
0
function SQL_GetResultFields($sql)
{
    global $conn, $db;
    if (!($res = mysql_db_query($db, $sql))) {
        echo mysql_error();
        exit;
    }
    $col = 0;
    while ($field_obj = mysql_fetch_field($res)) {
        $field_arr[$col] = $field_obj->name;
        $col++;
    }
    $record = 0;
    while ($row = mysql_fetch_array($res)) {
        $col = 0;
        while (isset($row[$col])) {
            $result_fields[$record][$field_arr[$col]] = $row[$col];
            $result_fields[$record][$col] = $row[$col];
            $col++;
        }
        $record++;
    }
    //mysql_close($conn);
    return $result_fields;
}
Exemple #6
0
function show_db_results($result)
{
    if ($result || mysql_errno == 0) {
        echo 'Query Info: ' . mysql_info();
        echo '<table class="eb_table">';
        if (mysql_num_rows($result) > 0) {
            $fields_num = mysql_num_fields($result);
            echo "<tr>";
            // printing table headers
            for ($i = 0; $i < $fields_num; $i++) {
                $field = mysql_fetch_field($result);
                echo "<th class='eb_th1'>{$field->table}<br/>{$field->name}</td>";
            }
            echo "</tr>";
            // printing table rows
            while ($row = mysql_fetch_row($result)) {
                echo "<tr>";
                // $row is array... foreach( .. ) puts every element
                // of $row to $cell variable
                foreach ($row as $cell) {
                    echo "<td class='eb_td'>{$cell}</td>";
                }
                echo "</tr>";
            }
        } else {
            echo "<tr><td colspan='" . ($i + 1) . "'>No Results found!</td></tr>";
        }
        echo "</table>";
    } else {
        echo "Error in running query :" . mysql_error();
    }
}
 public function scaffold($table_name, $class_name = '', $prefix = '_')
 {
     $db_name = Database::get_main_database();
     $sql = "SELECT * FROM `{$db_name}`.`{$table_name}` LIMIT 1";
     $fields = array();
     $unique_fields = array();
     $rs = Database::query($sql, null, __FILE__);
     while ($field = mysql_fetch_field($rs)) {
         $fields[] = $field;
         if ($field->primary_key) {
             /**
              * Could move that to an array to support multiple keys
              */
             $id_name = $field->name;
         }
         if ($field->unique_key | $field->primary_key) {
             $keys[] = $field->name;
         }
     }
     $name = $table_name;
     $class_name = ucfirst($table_name);
     ob_start();
     include dirname(__FILE__) . '/template/model.php';
     $result = ob_get_clean();
     return $result;
 }
Exemple #8
0
 function query_start($query)
 {
     // For reg expressions
     $query = trim($query);
     // Query was an insert, delete, update, replace
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         return false;
     }
     $this->savedqueries[] = $query;
     // Flush cached values..
     $this->flush();
     // Log how the function was called
     $this->func_call = "\$db->query_start(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Perform the query via std mysql_query function..
     $this->result = @mysql_query($query, $this->dbh);
     $this->num_queries++;
     // If there is an error then take note of it..
     if (mysql_error()) {
         $this->print_error();
         return false;
     }
     // Take note of column info
     $i = 0;
     while ($i < @mysql_num_fields($this->result)) {
         $this->col_info[$i] = @mysql_fetch_field($this->result);
         $i++;
     }
     $this->last_result = array();
     $this->num_rows = 0;
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return true;
 }
Exemple #9
0
function export_table2sql($result, $file)
{
    $handle = fopen($file . ".sql", "wb");
    $data = "";
    $i = 0;
    while ($i < mysql_num_fields($result) - 1) {
        $field = mysql_fetch_field($result, $i);
        $data .= $field->name . ";";
        $i++;
    }
    $field = mysql_fetch_field($result, $i);
    $data .= $field->name . "\n";
    //    fwrite($handle, $data);
    $data = "";
    $num_rows = mysql_num_rows($result);
    if ($num_rows == 0) {
    } else {
        for ($j = 0; $j < $num_rows; $j++) {
            $i = 0;
            $resultrow = mysql_fetch_assoc($result);
            fwrite($handle, "INSERT INTO {$file} VALUES (");
            while ($i < mysql_num_fields($result) - 1) {
                $field = mysql_fetch_field($result, $i);
                $data .= "'" . trim($resultrow[$field->name]) . "', ";
                $i++;
            }
            $field = mysql_fetch_field($result, $i);
            $data .= "'" . trim($resultrow[$field->name]) . "');\n";
            fwrite($handle, $data);
            $data = "";
        }
    }
    fclose($handle);
}
Exemple #10
0
 function getJSON($resultSet, $affectedRecords)
 {
     $numberRows = 0;
     $arrfieldName = array();
     $i = 0;
     $json = "";
     while ($i < mysql_num_fields($resultSet)) {
         $meta = mysql_fetch_field($resultSet, $i);
         if ($meta) {
             $arrfieldName[$i] = $meta->name;
         }
         $i++;
     }
     $i = 0;
     $json = "{\"status\":\"OK\",\"data\": [";
     while ($row = mysql_fetch_array($resultSet, MYSQL_NUM)) {
         $i++;
         $json .= "{";
         for ($r = 0; $r < count($arrfieldName); $r++) {
             $json .= "\"{$arrfieldName[$r]}\":\"" . str_replace("\"", "\\\"", $row[$r]) . "\"";
             if ($r < count($arrfieldName) - 1) {
                 $json .= ",";
             } else {
                 $json .= "";
             }
         }
         if ($i != $affectedRecords) {
             $json .= "},";
         } else {
             $json .= "}";
         }
     }
     $json .= "]}";
     return $json;
 }
 public function getColumnMeta($column)
 {
     if ($column >= $this->columnCount()) {
         return false;
     }
     $info = mysql_fetch_field($this->_result, $column);
     $result = array();
     if ($info->def) {
         $result['mysql:def'] = $info->def;
     }
     $result['native_type'] = $info->type;
     $result['flags'] = explode(' ', mysql_field_flags($this->_result, $column));
     $result['table'] = $info->table;
     $result['name'] = $info->name;
     $result['len'] = mysql_field_len($this->_result, $column);
     $result['precision'] = 0;
     switch ($result['native_type']) {
         // seems like pdo_mysql treats everything as a string
         /*
          * case 'int': case 'real': $pdo_type =
          * EhrlichAndreas_Pdo_Abstract::PARAM_INT; break; case 'blob': $pdo_type =
          * EhrlichAndreas_Pdo_Abstract::PARAM_LOB; break; case 'null': $pdo_type =
          * EhrlichAndreas_Pdo_Abstract::PARAM_NULL; break;
          */
         default:
             $pdo_type = EhrlichAndreas_Pdo_Abstract::PARAM_STR;
             break;
     }
     $result['pdo_type'] = $pdo_type;
     return $result;
 }
function get_gift_code_table()
{
    require_once 'mysqldb_lib.php';
    $query = "SELECT * FROM gift_type";
    $result = mysql_query($query);
    $table = "<table border=\"1\">\n";
    $table_header = "<tr>";
    for ($i = 0; $i < mysql_num_fields($result); $i++) {
        $meta = mysql_fetch_field($result, $i);
        $table_header .= "<th>" . $meta->name . "</th>";
    }
    $table_header .= "<th>Get Code</th>";
    $table_header .= "</tr>\n";
    $table_rows = "";
    while ($row = mysql_fetch_assoc($result)) {
        $table_rows .= "<tr>";
        foreach ($row as $field_value) {
            $table_rows .= "<td>{$field_value}</td>";
        }
        $table_rows .= "<td><a href=\"get_button_code.php?id={$row['type_id']}&name={$row['type_name']}&price={$row['price']}\" target=\"_blank\">[Get]</a></td>";
        $table_rows .= "</tr>\n";
    }
    $table .= $table_header . $table_rows;
    $table .= "</table>\n";
    return $table;
}
 function htmlitize($showFields = true)
 {
     $content = "";
     if ($showFields) {
         $fields = "";
         for ($i = 0; $i < $this->fieldCnt; ++$i) {
             $fields .= "<td><b>" . mysql_fetch_field($this->result, $i)->name . "</b></td>";
         }
         $content .= "<tr>{$fields}</tr>";
     }
     mysql_data_seek($this->result, 0);
     while (true) {
         $rowData = mysql_fetch_row($this->result);
         if ($rowData === false) {
             break;
         }
         $row = "";
         foreach ($rowData as $value) {
             $row .= "<td>{$value}</td>";
         }
         $content .= "<tr>{$row}</tr>";
     }
     // restore previous iterator position
     mysql_data_seek($this->result, $this->rowIter);
     return "<table border=\"1\" class=\"pure-table pure-table-bordered\">{$content}</table>";
 }
 function getFieldsInfo()
 {
     $result = array();
     while (($fInfo = mysql_fetch_field($this->rs)) != NULL) {
         $result[$fInfo->name] = $fInfo;
     }
     return $result;
 }
function PMA_mysql_fetch_field($result, $field_offset = FALSE)
{
    if ($field_offset != FALSE) {
        return PMA_convert_display_charset(mysql_fetch_field($result, $field_offset));
    } else {
        return PMA_convert_display_charset(mysql_fetch_field($result));
    }
}
 /**
  * Fetch Field Names
  *
  * Generates an array of column names
  *
  * @access	public
  * @return	array
  */
 function list_fields()
 {
     $field_names = array();
     while ($field = mysql_fetch_field($this->result_id)) {
         $field_names[] = $field->name;
     }
     return $field_names;
 }
 public function get_style_id()
 {
     if ($this->is_logged()) {
         $result = mysql_query("SELECT estilo FROM usuarios_opciones WHERE usuario = " . $this->get_user_id());
         return mysql_fetch_field($result);
     }
     return NULL;
 }
 function db_col_props($table)
 {
     $result = $this->db_query("SELECT * FROM `{$table}`");
     $array = array();
     while ($filed = mysql_fetch_field($result)) {
         $array[] = $filed;
     }
     return $array;
 }
Exemple #19
0
 function getFieldType($name, $res)
 {
     $len = mysql_num_fields($res);
     for ($i = 0; $i < $len; $i++) {
         if (($meta = mysql_fetch_field($res, $i)) && $meta->name == $name) {
             return $meta->type;
         }
     }
 }
Exemple #20
0
/**
 * The MysqlExportXls function is used to export mysql query result into an .xls file.
 * @param MysqlExportXlsConnectOptions $connectOptions
 * @param MysqlExportXlsFileOptions $fileOptions
 * @return error message. Return empty string on success.
 */
function MysqlExportXls($connectOptions, $fileOptions, $query)
{
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getProperties()->setCreator($fileOptions->creator);
    $objPHPExcel->getProperties()->setLastModifiedBy($fileOptions->lastModifiedBy);
    $objPHPExcel->getProperties()->setTitle($fileOptions->title);
    $objPHPExcel->getProperties()->setSubject($fileOptions->subject);
    $objPHPExcel->getProperties()->setDescription($fileOptions->description);
    $objPHPExcel->setActiveSheetIndex(0);
    $activeSheet = $objPHPExcel->getActiveSheet();
    $activeSheet->setTitle($fileOptions->title);
    // connect to mysql
    $link = mysql_connect($connectOptions->host, $connectOptions->userName, $connectOptions->password);
    if (!$link) {
        return __FILE__ . ":" . __FUNCTION__ . ':' . 'Could not connect: ' . mysql_error($link);
    }
    // use database
    $selectDb = mysql_select_db($connectOptions->useDatabase, $link);
    if (!$selectDb) {
        return __FILE__ . ":" . __FUNCTION__ . ':' . 'Could not select database' . mysql_error($link);
    }
    // PHPExcel use utf-8 encoding to save file only !!!
    $setCharset = mysql_set_charset("utf8", $link);
    if (!$setCharset) {
        return __FILE__ . ":" . __FUNCTION__ . ':' . 'Could not set charset' . mysql_error($link);
    }
    // execute sql
    $result = mysql_query($query, $link);
    if (!$result) {
        return __FILE__ . ":" . __FUNCTION__ . ':' . 'Query failed: ' . mysql_error($link);
    }
    // field names
    $columnIndex = 0;
    while ($field = mysql_fetch_field($result)) {
        $activeSheet->SetCellValue(PHPExcel_Cell::stringFromColumnIndex($columnIndex) . '1', $field->name);
        ++$columnIndex;
    }
    $rowIndex = 2;
    // 1 based, the firset row is for field names.
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $columnIndex = 0;
        foreach ($line as $key => $col_value) {
            $activeSheet->SetCellValue(PHPExcel_Cell::stringFromColumnIndex($columnIndex) . $rowIndex, $col_value === null ? "" : $col_value, PHPExcel_Cell_DataType::TYPE_STRING2);
            ++$columnIndex;
        }
        ++$rowIndex;
    }
    // free mysql resource
    mysql_free_result($result);
    mysql_close($link);
    // write data into file
    $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
    $objWriter->setPreCalculateFormulas(FALSE);
    // Why true by default ? oh god damn it!
    $objWriter->save($fileOptions->name);
    return "";
}
 function query($query)
 {
     // Flush cached values..
     $this->flush();
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Perform the query via std mysql_query function..
     $this->result = mysql_query($query, $this->dbh);
     // If there was an insert, delete or update see how many rows were affected
     // (Also, If there there was an insert take note of the insert_id
     $query_type = array("insert", "delete", "update", "replace");
     // loop through the above array
     foreach ($query_type as $word) {
         // This is true if the query starts with insert, delete or update
         if (preg_match("/^\\s*{$word} /i", $query)) {
             $this->rows_affected = mysql_affected_rows($this->dbh);
             // This gets the insert ID
             if ($word == "insert" || $word == "replace") {
                 $this->insert_id = mysql_insert_id($this->dbh);
             }
             $this->result = false;
         }
     }
     if (mysql_error()) {
         trigger_error(mysql_error(), E_USER_ERROR);
     } else {
         // In other words if this was a select statement..
         if ($this->result) {
             // =======================================================
             // Take note of column info
             $i = 0;
             while ($i < @mysql_num_fields($this->result)) {
                 $this->col_info[$i] = @mysql_fetch_field($this->result);
                 $i++;
             }
             // =======================================================
             // Store Query Results
             $i = 0;
             while ($row = @mysql_fetch_object($this->result)) {
                 // Store relults as an objects within main array
                 $this->last_result[$i] = $row;
                 $i++;
             }
             // Log number of rows the query returned
             $this->num_rows = $i;
             @mysql_free_result($this->result);
             // If there were results then return true for $db->query
             return $i ? true : false;
         } else {
             // Update insert etc. was good..
             return true;
         }
     }
 }
 function bkdata($size = '1024')
 {
     $output = '';
     $newline = "\r\n";
     $tables = $this->db->list_tables();
     foreach ((array) $tables as $table) {
         if (strpos($table, CS_SqlPrefix) !== FALSE) {
             $query = $this->db->query("SELECT * FROM {$table}");
             if ($query->num_rows() == 0) {
                 continue;
             }
             $i = 0;
             $field_str = '';
             $is_int = array();
             while ($field = mysql_fetch_field($query->result_id)) {
                 $is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)), array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), TRUE) ? TRUE : FALSE;
                 $field_str .= '`' . $field->name . '`, ';
                 $i++;
             }
             $field_str = preg_replace("/, \$/", "", $field_str);
             foreach ($query->result_array() as $row) {
                 $val_str = '';
                 $i = 0;
                 foreach ($row as $v) {
                     if ($v === NULL) {
                         $val_str .= 'NULL';
                     } else {
                         if ($is_int[$i] == FALSE) {
                             $val_str .= $this->db->escape($v);
                         } else {
                             $val_str .= $v;
                         }
                     }
                     $val_str .= ', ';
                     $i++;
                 }
                 $val_str = preg_replace("/, \$/", "", $val_str);
                 $output .= 'INSERT INTO ' . $table . ' (' . $field_str . ') VALUES (' . $val_str . ');' . $newline;
                 if (strlen($output) > $size * 1024) {
                     $bkfile = "./attachment/backup/Cscms_v4_" . date('Ymd') . "/datas_" . substr(md5(time() . mt_rand(1000, 5000)), 0, 16) . ".sql";
                     //名称
                     //写文件
                     write_file($bkfile, $output);
                     $output = "";
                 }
             }
             $output .= $newline . $newline;
         }
     }
     if (!empty($output)) {
         $bkfile = "./attachment/backup/Cscms_v4_" . date('Ymd') . "/datas_" . substr(md5(time() . mt_rand(1000, 5000)), 0, 16) . ".sql";
         //写文件
         write_file($bkfile, $output);
     }
     return TRUE;
 }
 function GetFieldNames()
 {
     $nbr = $this->NumFields();
     $flds = array();
     while ($nbr > 0) {
         $meta = mysql_fetch_field($this->iRes);
         $flds[] = $meta->name;
         --$nbr;
     }
 }
 function GetFields()
 {
     $_fields = array();
     $_result = mysql_query($this->SelectCommand, $this->_Link);
     while ($_prop = mysql_fetch_field($_result)) {
         $_field = array("Name" => $_prop->name, "Type" => $_prop->type, "Not_Null" => $_prop->not_null);
         array_push($_fields, $_field);
     }
     return $_fields;
 }
 function query($query)
 {
     // filter the query, if filters are available
     // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
     if (function_exists('apply_filters')) {
         $query = apply_filters('query', $query);
     }
     // initialise return
     $return_val = 0;
     $this->flush();
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Perform the query via std mysql_query function..
     if (SAVEQUERIES) {
         $this->timer_start();
     }
     $this->result = @mysql_query($query, $this->dbh);
     ++$this->num_queries;
     if (SAVEQUERIES) {
         $this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
     }
     // If there is an error then take note of it..
     if (mysql_error($this->dbh)) {
         $this->print_error();
         return false;
     }
     if (preg_match("/^\\s*(insert|delete|update|replace) /i", $query)) {
         $this->rows_affected = mysql_affected_rows($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^\\s*(insert|replace) /i", $query)) {
             $this->insert_id = mysql_insert_id($this->dbh);
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         $i = 0;
         while ($i < @mysql_num_fields($this->result)) {
             $this->col_info[$i] = @mysql_fetch_field($this->result);
             $i++;
         }
         $num_rows = 0;
         while ($row = @mysql_fetch_object($this->result)) {
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @mysql_free_result($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     return $return_val;
 }
Exemple #26
0
 public static function fetch()
 {
     $return = func_get_arg(0);
     $sql = func_get_arg(1);
     if (!$sql) {
         return false;
     }
     $fct_list = array('array', 'assoc', 'field', 'lengths', 'object', 'row');
     if (!in_array($return, $fct_list)) {
         $return = 'array';
     }
     // retourne une ligne de résultat mysql sous la forme d'un tableau associatif (MYSQL_ASSOC), d'un tableau indexé (MYSQL_NUM), ou les deux (MYSQL_BOTH)
     if ($return == 'array') {
         $result_type = func_num_args() >= 3 ? func_get_arg(2) : MYSQL_BOTH;
         //$this->driver->fetch_array()
         return mysql_fetch_array($sql, $result_type);
     } else {
         if ($return == 'assoc') {
             //$this->driver->fetch_assoc()
             return mysql_fetch_assoc($sql);
         } else {
             if ($return == 'field') {
                 // la position numérique du champ
                 // cf. http://fr3.php.net/manual/fr/function.mysql-fetch-field.php
                 $field_offset = func_num_args() >= 3 ? func_get_arg(2) : 0;
                 //$this->driver->fetch_field()
                 return mysql_fetch_field($sql, $field_offset);
             } else {
                 if ($return == 'lengths') {
                     //$this->driver->fetch_lengths()
                     return mysql_fetch_lengths($sql);
                 } else {
                     if ($return == 'object') {
                         // le nom de la class à instancier
                         $class_name = func_num_args() >= 3 ? func_get_arg(2) : 'stdClass';
                         // un tableau contenant les paramètres à passer au contructeur de la class $class_name
                         $params = func_num_args() >= 4 ? func_get_arg(3) : false;
                         if ($params) {
                             //$this->driver->fetch_object()
                             return mysql_fetch_object($sql, $class_name, $params);
                         } else {
                             //$this->driver->fetch_object()
                             return mysql_fetch_object($sql, $class_name);
                         }
                     } else {
                         if ($return == 'row') {
                             //$this->driver->fetch_row()
                             return mysql_fetch_row($sql);
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #27
0
 private function getColumnNames($result)
 {
     $names = array();
     $i = 0;
     while ($i < @mysql_num_fields($result)) {
         $meta = mysql_fetch_field($result, $i);
         array_push($names, $meta->name);
         $i++;
     }
     return $names;
 }
Exemple #28
0
  function GetColumns($result) {
  	//return mysql_fetch_field($result, $i);
  	$i = 0;
  	//echo mysql_num_fields($result);
  	$fields_arr[]="";
		for ($i=0;$i<mysql_num_fields($result);$i++) {
    	$meta= mysql_fetch_field($result, $i);
    	array_push($fields_arr,$meta->name);
    }
    return $fields_arr;
  }
 /**
  * Constructor
  *
  * @param   resource handle
  */
 public function __construct($result, TimeZone $tz = NULL)
 {
     $fields = array();
     if (is_resource($result)) {
         for ($i = 0, $num = mysql_num_fields($result); $i < $num; $i++) {
             $field = mysql_fetch_field($result, $i);
             $fields[$field->name] = $field->type;
         }
     }
     parent::__construct($result, $fields, $tz);
 }
Exemple #30
0
function _mysqldump_table_data($table)
{
    $sql = "select * from `{$table}`;";
    $result = mysql_query($sql);
    if ($result) {
        $num_rows = mysql_num_rows($result);
        $num_fields = mysql_num_fields($result);
        if ($num_rows > 0) {
            $sonuc .= "/* dumping data for table `{$table}` */\n";
            $field_type = array();
            $i = 0;
            while ($i < $num_fields) {
                $meta = mysql_fetch_field($result, $i);
                array_push($field_type, $meta->type);
                $i++;
            }
            //print_r( $field_type);
            $sonuc .= "insert into `{$table}` values\n";
            $index = 0;
            while ($row = mysql_fetch_row($result)) {
                $sonuc .= "(";
                for ($i = 0; $i < $num_fields; $i++) {
                    if (is_null($row[$i])) {
                        $sonuc .= "null";
                    } else {
                        switch ($field_type[$i]) {
                            case 'int':
                                $sonuc .= $row[$i];
                                break;
                            case 'string':
                            case 'blob':
                            default:
                                $sonuc .= "'" . $row[$i] . "'";
                        }
                    }
                    if ($i < $num_fields - 1) {
                        $sonuc .= ",";
                    }
                }
                $sonuc .= ")";
                if ($index < $num_rows - 1) {
                    $sonuc .= ",";
                } else {
                    $sonuc .= ";";
                }
                $sonuc .= "\n";
                $index++;
            }
        }
    }
    mysql_free_result($result);
    return $sonuc;
}