Chủ đề: Mysql_field_name
Có 1 bài viết
Hướng dẫn mysqli_fetch_field
[PHP 4, PHP 5]mysql_fetch_field — Get column information from a result and return as an objectDescriptionmysql_fetch_field[resource $result, int $field_offset = 0]: objectParameters resultThe ...
programming mysql Mysql_field_name Mysqli_result Mysqli_fetch_array PHP SQL MySQLi MySQL SELECT
- Trước
- 1
- 2
- 3
- 4
- 5
- 6
- Sau
[PHP 4, PHP 5] mysql_fetch_field — Get column information from a result and return as an object
Description
mysql_fetch_field[resource $result
, int $field_offset
= 0]: object
Parameters
result
The result resource that is being evaluated. This result comes from a call to mysql_query[].
field_offset
The numerical field offset. If the field offset is not specified, the next field that was not yet retrieved by this function is retrieved. The field_offset
starts at 0
.
Return Values
Returns an object containing field information. The properties of the object are:
- name - column name
- table - name of the table the column belongs to, which is the alias name if one is defined
- max_length - maximum length of the column
- not_null - 1 if the column cannot be
null
- primary_key - 1 if the column is a primary key
- unique_key - 1 if the column is a unique key
- multiple_key - 1 if the column is a non-unique key
- numeric - 1 if the column is numeric
- blob - 1 if the column is a BLOB
- type - the type of the column
- unsigned - 1 if the column is unsigned
- zerofill - 1 if the column is zero-filled
Examples
Example #1 mysql_fetch_field[] example
Notes
Note: Field names returned by this function are case-sensitive.
Note:
If field or tablenames are aliased in the SQL query the aliased name will be returned. The original name can be retrieved for instance by using mysqli_result::fetch_field[].
david at vitam dot be ¶
14 years ago
A little function to help coders to distinct the tablename from a multiselect query where some fields has the same name in differents tables.
Nick Baicoianu ¶
17 years ago
Be sure to note that $max_length is the length of the longest value for that field in the returned dataset, NOT the maximum length of data that column is designed to hold.
krang at krang dot org dot uk ¶
20 years ago
The field type returns what PHP classifies the data found in the field, not how it is stored in the database; use the following example to retrieve the MySQL information about the field....
jorachim at geemail dot com ¶
13 years ago
If you want the fields in a table, a simple DESCRIBE query will work:
Daniel B ¶
10 years ago
Simple function to display all data in a query...
function dumpquery[$query] {
$numfields = mysql_num_fields[$query];
echo '
'; '; ';
for [$i = 0; $iname . '';
}
echo '
while [$fielddata = mysql_fetch_array[$query]] {
echo ''; ';
for [$i = 0; $iname] . '';
}
echo '
}
echo '
}
TALU ¶
13 years ago
XML generation.
Bit of a security risk allowing parameters to select db and table on live server [unless user is restricted or replace the $_GET with fixed value.]
Outputs xml with standard format for part to generate forms in flash.
0]{
?>
>
>
php [spat] hm2k.org ¶
13 years ago
An improvement on the earlier mysql_column_exists function.
The field objects now have 'len', 'values' and 'flags' parameters.
NOTE: 'values' only has data for set and enum fields.
hope someone else finds this useful.
eviltofu at gmail dot com ¶
11 years ago
MYSQLI_TYPE_BLOB indicates the field is a BLOB or a TEXT. I think you would need to check the blob value. If its true then it's a BLOB, otherwise it's a TEXT. Can someone confirm?
dheep ¶
14 years ago
Simple PHP script for displaying the field names. Presuming the database is seleected already.
OUTPUt:
0.id
1.todo
2.due date
3.priority
4.type
5.status
6.notes
hope this is useful.