本文整理汇总了PHP中mysql_list_fields函数的典型用法代码示例。如果您正苦于以下问题:PHP mysql_list_fields函数的具体用法?PHP mysql_list_fields怎么用?PHP mysql_list_fields使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysql_list_fields函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dumpData
function dumpData($link, $mdb_name, $live_link)
{
$result = mysql_list_tables($mdb_name, $link);
while ($row = mysql_fetch_row($result)) {
$getdata = mysql_query("SELECT * FROM {$row['0']}", $link);
while ($row1 = mysql_fetch_array($getdata)) {
$thesql = "INSERT INTO `{$row['0']}` VALUES (";
$getcols = mysql_list_fields($mdb_name, $row[0], $link);
for ($c = 0; $c < mysql_num_fields($getcols); $c++) {
$thesql .= "'" . mysql_format($row1[$c]) . "'";
if ($c < mysql_num_fields($getcols) - 1) {
$thesql .= ",";
}
}
$thesql .= ")";
mysql_query("{$thesql}", $live_link);
unset($err);
$err = mysql_error();
if ($err) {
print "Query: " . $tok . "<br>";
print "Error: " . $err . "<br>";
} else {
print ".";
ob_flush();
flush();
}
$thesql = "";
}
}
return true;
}
示例2: check_database
function check_database()
{
# Initial table setup
/* Entries table */
if (!mysql_query("SELECT 1 FROM entries LIMIT 0")) {
mysql_query("\n CREATE TABLE `entries` (\n `entry_id` int(11) NOT NULL auto_increment,\n `startdate` date default NULL,\n `project_id` int(11) default NULL,\n `person_id` int(11) default NULL,\n PRIMARY KEY (`entry_id`)\n ) ENGINE=MyISAM AUTO_INCREMENT=191 DEFAULT CHARSET=latin1\n ");
}
/* People table */
if (!mysql_query("SELECT 1 FROM people LIMIT 0")) {
mysql_query("\n CREATE TABLE `people` (\n `person_id` int(11) NOT NULL auto_increment,\n `person_name` varchar(100) default NULL,\n `person_role` varchar(11) default NULL,\n PRIMARY KEY (`person_id`)\n) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=latin1\n ");
}
/* Projects table */
if (!mysql_query("SELECT 1 FROM projects LIMIT 0")) {
mysql_query("\n CREATE TABLE `projects` (\n `project_id` int(11) NOT NULL auto_increment,\n `project_name` varchar(100) default NULL,\n `sort_order` int(11) default NULL,\n `parked` varchar(20) default NULL,\n PRIMARY KEY (`project_id`)\n) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=latin1\n ");
}
/* Changes table */
if (!mysql_query("SELECT 1 FROM changes LIMIT 0")) {
mysql_query("\n CREATE TABLE `changes` (\n `change_id` int(11) NOT NULL auto_increment,\n `timestamp` datetime default NULL,\n `instigator` varchar(100) default NULL,\n `verb` varchar(100) default NULL,\n `person_id` int(11) default NULL,\n `preposition` varchar(100) default NULL,\n `project_id` int(11) default NULL,\n `week` varchar(100) default NULL,\n PRIMARY KEY (`change_id`)\n) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=latin1\n ");
}
/* Options table */
if (!mysql_query("SELECT 1 FROM options LIMIT 0")) {
mysql_query("\n CREATE TABLE `options` (\n `option_id` int(11) NOT NULL auto_increment,\n `option_name` varchar(100) default NULL,\n `option_value` text default NULL,\n PRIMARY KEY (`option_id`)\n) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=latin1\n ");
}
#
# add "project_url" field to projects table */
#
$fields = mysql_list_fields(DB_NAME, 'projects');
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
$field_array[] = mysql_field_name($fields, $i);
}
if (!in_array('project_url', $field_array)) {
$result = mysql_query('ALTER TABLE projects ADD project_url text');
}
# end project_url
#
# add "person_long_name" field to people table */
#
$fields = mysql_list_fields(DB_NAME, 'people');
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
$field_array[] = mysql_field_name($fields, $i);
}
if (!in_array('person_long_name', $field_array)) {
$result = mysql_query('ALTER TABLE people ADD person_long_name VARCHAR(200)');
}
# end project_url
#
# Versions after 0.3
#
/* Assuming all went well, bump DB # */
$q = mysql_query('SELECT option_value FROM options WHERE option_name = "db_version"');
$r = mysql_fetch_row($q);
if (!$r) {
mysql_query('INSERT INTO options (option_name, option_value) VALUES ("db_version", ' . CODE_VERSION . ')');
} else {
mysql_query('UPDATE options SET option_value = "' . CODE_VERSION . '" where option_name = "db_version"');
}
}
示例3: list_fields
function list_fields($tableName)
{
$fields = mysql_list_fields($this->db_name, $tableName, $this->connect);
$columns = mysql_num_fields($fields);
$f = array();
for ($i = 0; $i < $columns; $i++) {
array_push($f, mysql_field_name($fields, $i));
}
return $f;
}
示例4: getTableField
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;
}
示例5: name_fields
function name_fields($table)
{
$vet = array();
$campi = mysql_list_fields($this->database, $table, $this->link_id);
$colonne = mysql_num_fields($campi);
for ($i = 0; $i < $colonne; $i++) {
$vet[] = mysql_field_name($campi, $i);
}
return $vet;
}
示例6: readTables
function readTables()
{
$link = mysql_connect('localhost', 'root', 'M2oNa3D9');
$result = mysql_list_tables('test', $link);
$tables = array();
while ($row = mysql_fetch_row($result)) {
$name = $row[0];
$columns = self::readColumns(mysql_list_fields('album', $name, $link));
$keys = self::readKeys(mysql_list_fields('album', $name, $link));
$tables[$name] = array('columns' => $columns, 'keys' => $keys);
}
return $tables;
}
示例7: getTablePrimeKey
function getTablePrimeKey($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);
if (in_array("primary_key", explode(" ", mysql_field_flags($fields, $i)))) {
$return[] = $field_name;
}
}
return $return;
}
示例8: st_check_field
function st_check_field($tableName, $columnName)
{
//Getting table fields through mysql built in function, passing db name and table name
$tableFields = mysql_list_fields(DB_DATABASE, $tableName);
//loop to traverse tableFields result set
for ($i = 0; $i < mysql_num_fields($tableFields); $i++) {
//Using mysql_field_name function to compare with column name passed. If they are same function returns 1
if (mysql_field_name($tableFields, $i) == $columnName) {
return true;
}
}
//end of loop
return false;
}
示例9: db_insert
function db_insert($table, $array)
{
//插入数据 数组array是传递过来的,要求字符串下标必须与数据库中字段名称相同
$head = mysql_list_fields("{$this->dbname}", "{$table}", $this->hwnd);
$count = mysql_num_fields($head);
$field = mysql_field_name($head, 1);
$value = "\"" . $array[mysql_field_name($head, 1)] . "\"";
for ($i = 2; $i < $count; $i++) {
$field = $field . "," . mysql_field_name($head, $i);
$value = $value . "," . "\"" . $array[mysql_field_name($head, $i)] . "\"";
}
$chaxun = "insert into {$table}({$field}) values({$value})";
$resu = mysql_query($chaxun, $this->hwnd);
return $resu;
}
示例10: meta
function meta($table, $schema = "DEFAULT") {
$db = $GLOBALS["CFG_DB"]->CON[$schema]->DB;
$link = MysqlDriver::connect($schema);
$result = mysql_list_fields($db, $table, $link);
$count = mysql_num_fields($result);
$fields = array();
for($i = 0; $i < $count; $i++) {
$field["name"] = mysql_field_name($result, $i);
$field["length"] = mysql_field_len($result, $i);
$field["type"] = mysql_field_type($result, $i);
$field["flags"] = mysql_field_flags($result, $i);
$fields[] = $field;
}
mysql_free_result($result);
return $fields;
}
示例11: get_table_metadata
/**
* All information about a table columns
*
* @return array di nomi di colonne e relative info in formato mysql
*/
public function get_table_metadata($table_name)
{
$metadata = null;
$list_fields = mysql_list_fields($this->user_db, $table_name);
if (!$list_fields) {
$this->set_error("DB Error, could not get metadata.");
return $metadata;
}
$num_fields = mysql_num_fields($list_fields);
for ($i = 0; $i < $num_fields && ($info_field = mysql_fetch_field($list_fields, $i)); $i++) {
// aggiungi field flags e salva table metadata
$info_field->field_flags = mysql_field_flags($list_fields, $i);
$metadata[$info_field->name] = $info_field;
}
return $metadata;
}
示例12: find_db_column
function find_db_column($table, $column)
{
// Better return values than SHOW COLUMNS but mysql_ commands are being depreciated. Migrate to mysqli_ commands instead.
$connectstr = @parse_url(MYACTIVERECORD_CONNECTION_STR) or trigger_error("MyActiveRecord::Connection() - could not parse connection string: " . MYACTIVERECORD_CONNECTION_STR, E_USER_ERROR);
$dbname = trim($connectstr['path'], ' /');
$fields = mysql_list_fields($dbname, $table);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
$field_array[] = mysql_field_name($fields, $i);
}
if (in_array($column, $field_array)) {
return true;
} else {
return false;
}
}
示例13: GetFields
/**
* Function: GetFields
* Purpose: Returns an array of the fields
*/
function GetFields($table_name)
{
$result = mysql_list_fields($GLOBALS[dbname], "{$GLOBALS['prefix']}_{$table_name}");
$total = mysql_num_fields($result);
for ($i = 0; $i < $total; $i++) {
// name
$field_name = mysql_field_name($result, $i);
// type & size
$result2 = mysql_query("desc {$GLOBALS['prefix']}_{$table_name}");
while ($row = mysql_fetch_array($result2)) {
if ($row[Field] == $field_name) {
$field_type = $row[Type];
$field_default = $row['Default'];
}
}
if (strstr($field_type, '(')) {
$data = explode('(', $field_type);
$data2 = explode(')', $data[1]);
$field_type = $data[0];
$field_size = $data2[0];
} else {
$field_size = mysql_field_len($result, $i);
}
// flags
$field_flags = '';
$flags = explode(' ', mysql_field_flags($result, $i));
foreach ($flags as $k => $v) {
// just makes things easer :-)
$field_flags[$v] = true;
}
// put it all together
$fields[$field_name] = array('type' => $field_type, 'def' => $field_default, 'auto_increment' => $field_flags[auto_increment], 'binary' => $field_flags[binary], 'blob' => $field_flags[blob], 'enum' => $field_flags[enum], 'multiple_key' => $field_flags[multiple_key], 'not_null' => $field_flags[not_null], 'primary_key' => $field_flags[primary_key], 'timestamp' => $field_flags[timestamp], 'unique_key' => $field_flags[unique_key], 'unsigned' => $field_flags[unsigned], 'zerofill' => $field_flags[zero_fill]);
switch ($field_type) {
// need to add enum/set code someday
case 'float':
case 'decimal':
$fsize = explode(',', $field_size);
$fields[$field_name][size] = $fsize[0];
$fields[$field_name][fraction] = $fsize[1];
break;
default:
$fields[$field_name][size] = $field_size;
break;
}
}
return $fields;
}
示例14: mid_sqlparaexcel
function mid_sqlparaexcel($banco, $tabela, $sql, $arquivo)
{
$arquivo = trim($arquivo);
// define nome do arquivo
$this->nomeDoArquivoXls = $arquivo;
$this->nomeDoArquivoXls = $arquivo;
//Pega campos da tabela
$consTable = mysql_list_fields($banco, $tabela);
$linTable = mysql_num_fields($consTable);
echo mysql_error();
// Colsulta
$consReg = mysql_query($sql);
$linReg = mysql_num_rows($consReg);
// quantidade de colunas da tabela
$qtdColunas = $linTable;
// quadro 1, primeira linha, da primeira coluna X/Y
$excel_linha = 0;
$excel_coluna = 0;
for ($e = 0; $e < $qtdColunas; $e++) {
$vCampo = mysql_field_name($consTable, $e);
$vCampox = trim(ucwords(str_replace("_", " ", $vCampo)));
$this->MontaConteudo(0, $e, $vCampox);
}
// linha em branco
$this->MontaConteudo(1, 0, " ");
$this->MontaConteudo(1, 1, " ");
// Monta Colunas
for ($excel_coluna = 0; $excel_coluna < $qtdColunas; $excel_coluna++) {
// nome da coluna
$nome_coluna = mysql_field_name($consTable, $excel_coluna);
// Monta Linhas
for ($i = 0; $i < $linReg; $i++) {
//pega registros
$valorCelula = mysql_result($consReg, $i, $nome_coluna);
//linhas, começa depos do cabecario
//$excel_linha = ($i + 2);
$excel_linha = $i + 2;
$this->MontaConteudo($excel_linha, $excel_coluna, $valorCelula);
}
// fecha for 'Linhas'
}
// fecha for 'Colunas'
// Cria arquivo
$this->GeraArquivo();
}
示例15: getConfig
function getConfig()
{
global $conf_mysql_db;
$query = "SELECT * FROM config WHERE 1 LIMIT 1;";
$result = mysql_query($query) or die("Cannot query {$query} !!!" . mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows != 1) {
die("No config values in table !!!");
}
$row = mysql_fetch_array($result);
$fields = mysql_list_fields($conf_mysql_db, "config");
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
$field_name = mysql_field_name($fields, $i);
$toto = "conf_" . $field_name;
global ${$toto};
${$toto} = $row["{$field_name}"];
}
}