mysql_fetch_fieldSynopsis
Descriptionmysql_fetch_field() retrieves the column information for a field in a query. If you specify an offset to mysql_fetch_field() , the column properties for that field are returned. If you don't specify an offset, the data for the next field in order will be returned. The column information is returned as an object containing one or more of the properties from the following table. (Note: BLOB is an abbreviation of Binary Long OBject).
See also
ExampleExample 804. Fetch all column data from a result handle returned by mysql_query() <pre> <?php // Included code that connects to a MySQL server and sets a default database // See the MySQL Functions chapter introduction for the source code for the file include ('mysql_connect.inc.php'); // Make a simple SELECT query $query = "SELECT * FROM user"; $mysql_result = @ mysql_query ($query) or die ("Query '$query' failed with error message: \"" . mysql_error () . '"'); // Fetch the column data while ($column_data = mysql_fetch_field ($mysql_result)) { // Display the column name echo '<font size="+1"><b>', $column_data->name, '</b></font><blockquote>'; // Show every property of the column that is set foreach (get_object_vars ($column_data) as $key => $value) { if ($value && $key != 'name') { printf ("<b>%'.-24s</b>%s\n", $key, $value); } } echo "</blockquote><br />"; } ?> </pre> Example 805. Demonstrate how mysql_fetch_field() handles expressions and aliases <pre> <?php // Included code that connects to a MySQL server and sets a default database // See the MySQL Functions chapter introduction for the source code for the file include ('mysql_connect.inc.php'); // Make a simple SELECT query. // Note how the second call to curtime() is coerced into being a number // by adding zero (0) to it. Look at the script output for more info. $query = "SELECT year(curdate()), curtime(), curtime()+0 as time, user() as user"; $mysql_result = @ mysql_query ($query) or die ("Query '$query' failed with error message: \"" . mysql_error () . '"'); // Fetch the column data while ($column_data = mysql_fetch_field ($mysql_result)) { // Display the column name echo '<font size="+1"><b>', $column_data->name, '</b></font><blockquote>'; // Show every property of the column that is set foreach (get_object_vars ($column_data) as $key => $value) { if ($value && $key != 'name') printf ("<b>%'.-24s</b>%s\n", $key, $value); } echo "</blockquote><br />"; } ?> </pre> Example 806. Use mysql_fetch_field() and mysql_list_fields() together <pre> <?php // Included code that connects to a MySQL server and sets a default database // See the MySQL Functions chapter introduction for the source code for the file include ('mysql_connect.inc.php'); $table = 'user'; $mysql_result = @ mysql_list_fields ($db, $table) or die ("Could not list the fields for table '$table' in database '$db'."); // Fetch the column data while ($column_data = mysql_fetch_field ($mysql_result)) { // Display the column name echo '<font size="+1"><b>', $column_data->name, '</b></font><blockquote>'; // Show every property of the column that is set foreach (get_object_vars ($column_data) as $key => $value) { if ($value && $key != 'name') printf ("<b>%'.-24s</b>%s\n", $key, $value); } echo "</blockquote><br />"; } ?> </pre>
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|