function getAccessInfo($sql_fields, $sql_table, $sql_conditions = "1", $cond = NULL) { $access['Data'] = array(); $access['Headers'] = 0; $access['Sql_Fields'] = $sql_fields; $access['Sql_Table'] = $sql_table; $access['Sql_Conditions'] = $sql_conditions; $sql = "Select {$sql_fields} from {$sql_table} where {$sql_conditions}"; $result = sql_query_read($sql) or dieLog(mysql_error() . " ~ " . "<pre>{$sql}</pre>"); if (mysql_num_rows($result) < 1) { return -1; } $row = mysql_fetch_row($result); $fields = mysql_num_fields($result); for ($i = 0; $i < $fields; $i++) { $type = mysql_field_type($result, $i); $name = mysql_field_name($result, $i); $len = mysql_field_len($result, $i); $flags = mysql_field_flags($result, $i); $table = mysql_field_table($result, $i); $useName = $name; if (array_key_exists($useName, $access['Data'])) { $useName = $name . $i; } if ($name == 'access_header') { $access['Headers']++; } $access['Data'][$useName] = getAttrib($name, $type, $len, $flags, $table, $row[$i], &$cond); } return $access; }
function generateForm($tables) { $db = connect(); $num_tables = count($tables); if ($db) { echo "<html> \n<body>\n"; echo "<br /> <b> INSERT DATA </b> <br />\n"; echo "<br />Warning: Table does not correctly insert into multiple tables simultaneously\n"; echo "<form action=\"Data_insert.php\" method=\"post\">\n"; $result = mysql_query("SELECT * FROM " . $tables[$i], $db); for ($i = 0; $i < $num_tables; $i++) { $result = mysql_query("SELECT * FROM " . $tables[$i], $db); $keys = array_keys(mysql_fetch_assoc($result)); for ($j = 0; $j < count($keys); $j++) { $types[$j] = mysql_field_type($result, $j); } $iterations = count($keys); echo "<br /> <b> " . $tables[$i] . "</b> <br /> <br />\n"; for ($k = 1; $k < $iterations; $k++) { printf("%20s : <input type= \"%s\" name=\"%s\" /><br />\n", $keys[$k], $types[$k], $keys[$k]); } } echo "<input type=\"submit\" />\n </form>\n </html>\n</body> <br />"; $db = disconnect($db, $result); } }
/** * 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 mysqlfAdapter($d) { $f = $d['filter']; $d = $d['data']; parent::RecordSetAdapter($d); $fieldcount = count($f); $truefieldcount = mysql_num_fields($d); $be = $this->isBigEndian; $isintcache = array(); for ($i = 0; $i < $truefieldcount; $i++) { //mysql_fetch_* usually returns only strings, //hack it into submission $type = mysql_field_type($d, $i); $name = mysql_field_name($d, $i); $isintcache[$name] = in_array($type, array('int', 'real', 'year')); } $isint = array(); for ($i = 0; $i < $fieldcount; $i++) { $this->columnNames[$i] = $this->_charsetHandler->transliterate($f[$i]); $isint[$i] = isset($isintcache[$f[$i]]) && $isintcache[$f[$i]]; } //Start fast serializing $ob = ""; $fc = pack('N', $fieldcount); if (mysql_num_rows($d) > 0) { mysql_data_seek($d, 0); while ($line = mysql_fetch_assoc($d)) { //Write array flag + length $ob .= "\n" . $fc; $i = 0; foreach ($f as $key) { $value = $line[$key]; if (!$isint[$i]) { $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; } } else { $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; } $i++; } } } $this->numRows = mysql_num_rows($d); $this->serializedData = $ob; }
function Tabler($table, $cols = array(), $filters = array(), $order = "") { $this->table($table); $this->pager = new Pager(); if (count($cols) == 0) { $what = '*'; } else { foreach ($cols as $title => $name) { if ($name != "") { $this->addCol($name); $this->col_option($name, 'title', $title); } $what .= $name . ','; } $what = substr($what, 0, strlen($what) - 1); } if (count($filters) > 0) { foreach ($filters as $add) { $filter = isset($filter) ? "{$filter} AND {$add}" : " WHERE {$add}"; } } foreach ($_GET as $key => $value) { if (ereg('^filter_', $key)) { $name = substr($key, 7); if ($value != '') { if ($_GET['f_' . $name . '_type'] == 'search') { $filter = isset($filter) ? "{$filter} AND {$name} LIKE '%{$value}%'" : " WHERE {$name} LIKE '%{$value}%'"; } else { $filter = isset($filter) ? "{$filter} AND {$name}='{$value}'" : " WHERE {$name}='{$value}'"; } } } } $query = "SELECT count(*) as max FROM {$table} {$filter}"; $result = mysql_query($query) or die("MySQL Error: " . mysql_error()); $row = mysql_fetch_array($result); $this->pager->max($row['max']); $query = "SELECT {$what} FROM {$table} {$filter}"; $keys = array_keys($this->cols); $order = isset($_GET['orderby']) ? $_GET['orderby'] : ($order == "" ? $keys['0'] . ' DESC' : $order); $query .= " ORDER BY {$order}"; $query .= " LIMIT " . $this->pager->from() . "," . $this->pager->incr(); $result = mysql_query($query) or die("MySQL Error: " . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $this->add($row); } $fields = mysql_num_fields($result); for ($x = 0; $x < $fields; $x++) { $colinfo = @mysql_field_flags($result, $x); $colinfo = explode(' ', $colinfo); $name = mysql_field_name($result, $x); $type = mysql_field_type($result, $x); if (array_search('auto_increment', $colinfo) !== false) { $this->col_option($name, 'filter', 'submit'); $this->idcol = $name; } else { $this->col_option($name, 'filter', 'select'); } } }
/** * Field data * * Generates an array of objects containing field meta-data * * @access public * @return array */ function field_data() { $retval = array(); for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { $retval[$i] = new stdClass(); $retval[$i]->name = mysql_field_name($this->result_id, $i); $retval[$i]->type = mysql_field_type($this->result_id, $i); $retval[$i]->max_length = mysql_field_len($this->result_id, $i); $retval[$i]->primary_key = strpos(mysql_field_flags($this->result_id, $i), 'primary_key') === FALSE ? 0 : 1; $retval[$i]->default = ''; } /** Updated from github, see https://github.com/EllisLab/CodeIgniter/commit/effd0133b3fa805e21ec934196e8e7d75608ba00 while ($field = mysql_fetch_object($this->result_id)) { preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL; $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; $F = new stdClass(); $F->name = $field->Field; $F->type = $type; $F->default = $field->Default; $F->max_length = $length; $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); $retval[] = $F; } **/ return $retval; }
public function fetchArrayStrict($sql = null) { if (empty($sql)) { throw new DbException('<b>SQL ERROR</b> : null query ! <br>'); } $query = $this->query($sql); if ($query === false) { return null; } $confunc = $this->connect->getDbStyle() . '_fetch_array'; while ($arr = $confunc($query)) { $array[] = $arr; } if (!is_array($array)) { return null; } foreach ($array as $k => $v) { foreach ($v as $kk => $vv) { if (!is_numeric($kk)) { continue; } $type = mysql_field_type($query, $kk); $name = mysql_field_name($query, $kk); if ($type == 'int') { $arr[$k][$name] = (int) $vv; } else { $arr[$k][$name] = $vv; } } } return $arr; }
function getTypes() { $numFields = mysql_num_fields($this->result); $types = array(); for ($i = 0; $i < $numFields; $i++) { $types[] = $this->translateType(mysql_field_type($this->result, $i)); } return $types; }
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; }
public function getResultFields() { if (empty($this->resultFields)) { $numFields = mysql_num_fields($this->resultResource); for ($i = 0; $i < $numFields; $i++) { $this->resultFields[$i] = array("name" => mysql_field_name($this->resultResource, $i), "type" => mysql_field_type($this->resultResource, $i)); } } return $this->resultFields; }
function getTableField($table) { $this->connect(); $fields = mysql_list_fields($this->Database, $table, $this->Link_ID); $columns = mysql_num_fields($fields); for ($i = 0; $i < $columns; $i++) { $result[] = array('name' => mysql_field_name($fields, $i), 'type' => mysql_field_type($fields, $i)); } return $result; }
function getFields($table) { $this->execute("select * from {$table} limit 1"); for ($i = 0; $i < $this->numFields(); ++$i) { $fnames[] = mysql_field_name($this->ress, $i); $ftypes[] = mysql_field_type($this->ress, $i); } $this->fields = $fnames; $this->types = $ftypes; }
function backup_tables($tables = '*') { //get all of the tables if ($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while ($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',', $tables); } //cycle through foreach ($tables as $table) { echo "<div>Backing up table : {$table}</div>"; $result = mysql_query('SELECT * FROM ' . $table); $num_fields = mysql_num_fields($result); $return .= 'DROP TABLE ' . $table . ';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE ' . $table)); $return .= "\n\n" . $row2[1] . ";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while ($row = mysql_fetch_row($result)) { $return .= 'INSERT INTO ' . $table . ' VALUES('; for ($j = 0; $j < $num_fields; $j++) { $type = mysql_field_type($result, $j); if ($type == "blob") { $row[$j] = bin2hex($row[$j]); if (isset($row[$j])) { $return .= '0x' . $row[$j]; } else { $return .= '""'; } } else { $row[$j] = mysql_escape_string($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('backup/db-backup-' . time() . '-' . md5(implode(',', $tables)) . '.sql', 'w+'); fwrite($handle, $return); fclose($handle); echo "<h2>Done</h2>"; }
function readColumns($result) { $columns = array(); $column_num = mysql_num_fields($result); for ($i = 0; $i < $column_num; $i++) { $name = mysql_field_name($result, $i); $type = mysql_field_type($result, $i); $conums[$name] = array('type' => $type); } return $conums; }
function dumpMySQL($serveur, $login, $password, $base, $mode) { $connexion = mysql_connect($serveur, $login, $password); mysql_select_db($base, $connexion); $entete = "-- ----------------------\n"; $entete .= "-- dump de la base " . $base . " au " . date("d-M-Y") . "\n"; $entete .= "-- ----------------------\n\n\n"; $creations = ""; $insertions = "\n\n"; $listeTables = mysql_query("show tables", $connexion); while ($table = mysql_fetch_array($listeTables)) { // si l'utilisateur a demandé la structure ou la totale if ($mode == 1 || $mode == 3) { $creations .= "-- -----------------------------\n"; $creations .= "-- creation de la table " . $table[0] . "\n"; $creations .= "-- -----------------------------\n"; $listeCreationsTables = mysql_query("show create table " . $table[0], $connexion); while ($creationTable = mysql_fetch_array($listeCreationsTables)) { $creations .= $creationTable[1] . ";\n\n"; } } // si l'utilisateur a demandé les données ou la totale if ($mode > 1) { $donnees = mysql_query("SELECT * FROM " . $table[0]); $insertions .= "-- -----------------------------\n"; $insertions .= "-- insertions dans la table " . $table[0] . "\n"; $insertions .= "-- -----------------------------\n"; while ($nuplet = mysql_fetch_array($donnees)) { $insertions .= "INSERT INTO " . $table[0] . " VALUES("; for ($i = 0; $i < mysql_num_fields($donnees); $i++) { if ($i != 0) { $insertions .= ", "; } if (mysql_field_type($donnees, $i) == "string" || mysql_field_type($donnees, $i) == "blob") { $insertions .= "'"; } $insertions .= addslashes($nuplet[$i]); if (mysql_field_type($donnees, $i) == "string" || mysql_field_type($donnees, $i) == "blob") { $insertions .= "'"; } } $insertions .= ");\n"; } $insertions .= "\n"; } } mysql_close($connexion); $fichierDump = fopen("dump.sql", "w"); fwrite($fichierDump, $entete); fwrite($fichierDump, $creations); fwrite($fichierDump, $insertions); fclose($fichierDump); echo "Sauvegarde réalisée avec succès !!"; }
function _performGetBlobFieldNames($result) { $blobFields = array(); for ($i = mysql_num_fields($result) - 1; $i >= 0; $i--) { $type = mysql_field_type($result, $i); if (strpos($type, "BLOB") !== false) { $blobFields[] = mysql_field_name($result, $i); } } return $blobFields; }
public function db_metadata($table) { $result = $this->db_query("SELECT * FROM {$table} limit 1"); $fields = mysql_num_fields($result); $store = array(); for ($i = 0; $i < $fields; $i++) { $type = mysql_field_type($result, $i); $name = mysql_field_name($result, $i); $store[$name] = $type; } return $store; }
function field_type($query, $index) { switch ($this->sql) { case "mysql": return mysql_field_type($query, $index); break; default: $this->error($this->sql . " is not supported yet", "field_type"); return false; break; } }
function detectFieldTypes(&$result) { $field_types = array(); $num_fields = @mysql_num_fields($result); if (!$num_fields) { return array(); } for ($i = 0; $i < $num_fields; $i++) { $field_types[] = mysql_field_type($result, $i); } return $field_types; }
function sql_fieldtype($offset, $query_id = 0) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { $result = @mysql_field_type($query_id, $offset); return $result; } else { return false; } }
function get_fields($query_id) { $fields = $this->num_fields($query_id); $rows = $this->num_rows($query_id); for ($i = 0; $i < $fields; $i++) { $field[$i]->type = mysql_field_type($query_id, $i); $field[$i]->name = mysql_field_name($query_id, $i); $field[$i]->len = mysql_field_len($query_id, $i); $field[$i]->flags = mysql_field_flags($query_id, $i); } return $field; }
public function fields() { $fields = array(); if (!\mysql_num_fields($this->data)) { die('%\\sql\\SQL_Result.fields(): ' . \mysql_error()); } $num_fields = \mysql_num_fields($this->data); for ($f = 0; $f < $num_fields; ++$f) { $fields[] = array('name' => \mysql_field_name($this->data, $f), 'type' => \mysql_field_type($this->data, $f)); } return $fields; }
function _getFieldInfo($tableName) { $fieldInfo = array(); $sql = "SELECT * FROM {$tableName} LIMIT 1"; $result = mysql_query($sql, $this->_mysql_link_id); $num_field = mysql_num_fields($result); for ($i = 0; $i < $num_field; $i++) { $field_name = mysql_field_name($result, $i); $field_type = mysql_field_type($result, $i); $fieldInfo[$field_name] = $field_type; } mysql_free_result($result); return $fieldInfo; }
function getTableFieldHash($pTable) { $this->connectDB(); $fields = mysql_list_fields($this->mDatabaseName, $pTable, $this->mLink); $columns = mysql_num_fields($fields); for ($i = 0; $i < $columns; $i++) { $field_name = mysql_field_name($fields, $i); $return[$field_name]['name'] = $field_name; $return[$field_name]['type'] = mysql_field_type($fields, $i); $return[$field_name]['length'] = mysql_field_len($fields, $i); $return[$field_name]['flags'] = explode(" ", mysql_field_flags($fields, $i)); } return $return; }
function detectFieldTypes($table_name) { global $db; $field_types = array(); $sql = "SELECT * FROM " . TABLE_PREFIX . $table_name . ' WHERE 0'; $result = @mysql_query($sql, $db); if (!$result) { return array(); } $num_fields = mysql_num_fields($result); for ($i = 0; $i < $num_fields; $i++) { $field_types[] = mysql_field_type($result, $i); } return $field_types; }
public function getFieldsDescription() { if ($this->_fieldsDesc === null) { $this->_fieldsDesc = new _hx_array(array()); $_g1 = 0; $_g = $this->getNFields(); while ($_g1 < $_g) { $i = $_g1++; $item = _hx_anonymous(array("name" => mysql_field_name($this->__r, $i), "type" => mysql_field_type($this->__r, $i))); $this->_fieldsDesc->push($item); unset($item, $i); } } return $this->_fieldsDesc; }
} break; case "mysqli": $port = (int) $port; $GLOBALS["___mysqli_ston"] = mysqli_connect($host, $username, $password, $db_name, $port); $ret = $GLOBALS["___mysqli_ston"]; break; } return $ret; } function yog_mysql_field_type($result, $offset) { //Get the type of the specified field in a result $ret = 0; switch (DB_EXTENSION) {
public static function fireSQL($sql) { if (self::$_isValid) { $result = @mysql_query("SET NAMES cp1251", self::$_link); $result = @mysql_query($sql, self::$_link); if (!$result) { self::raiseException(ERR_MYSQL_INVALID_QUERY, mysql_error()); return false; } /* else */ if (@mysql_num_rows($result) === FALSE) { return mysql_affected_rows() || $result; } /* else */ $res = NULL; $ind = -1; $fields = mysql_num_fields($result); while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { $res = !isset($res) ? array() : $res; $k_num = -1; $ind++; foreach ($row as $k => $v) { if (!is_integer($k)) { $k_num++; $type = mysql_field_type($result, $k_num); switch ($type) { case "int": $res[$ind][$k] = (int) $v; break; case "real": $res[$ind][$k] = (double) $v; break; default: $res[$ind][$k] = $v; } } } } mysql_free_result($result); return $res; } else { //self::raiseException( ERR_MYSQL_INVALID_QUERY, mysql_error() ); return NULL; } }
/** * Returns an array of fields according to columns in the result. * * @return \Bitrix\Main\Entity\ScalarField[] */ public function getFields() { if ($this->resultFields == null) { $this->resultFields = array(); if (is_resource($this->resource)) { $numFields = mysql_num_fields($this->resource); if ($numFields > 0 && $this->connection) { $helper = $this->connection->getSqlHelper(); for ($i = 0; $i < $numFields; $i++) { $name = mysql_field_name($this->resource, $i); $type = mysql_field_type($this->resource, $i); $this->resultFields[$name] = $helper->getFieldByColumnType($name, $type); } } } } return $this->resultFields; }
/** * Parse resource into array * * @param resource $resource * @return array */ public function parse($resource) { $result = array(); $fieldcnt = mysql_num_fields($resource); $fields_transform = array(); for ($i = 0; $i < $fieldcnt; $i++) { $type = mysql_field_type($resource, $i); if (isset(self::$fieldTypes[$type])) { $fields_transform[mysql_field_name($resource, $i)] = self::$fieldTypes[$type]; } } while ($row = mysql_fetch_object($resource)) { foreach ($fields_transform as $fieldname => $fieldtype) { settype($row->{$fieldname}, $fieldtype); } $result[] = $row; } return $result; }
/** * 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 mysqlAdapter($d) { parent::RecordSetAdapter($d); $fieldcount = mysql_num_fields($d); $intFields = array(); for ($i = 0; $i < $fieldcount; $i++) { $this->columns[] = mysql_field_name($d, $i); $type = mysql_field_type($d, $i); if (in_array($type, array('int', 'real', 'year'))) { $intFields[] = $i; } } while ($row = mysql_fetch_row($d)) { foreach ($intFields as $key => $val) { $row[$val] = (double) $row[$val]; } $this->rows[] = $row; } }