count = -1;while (++$count < mysql_numrows($tables)) { echo mysql_tablename($tables, $count)."<br />";}
该函数获取mysql_list_tables()所返回result_set中位于指定index索引的表名获取字段信息
mysql_fetch_field()
object mysql_fetch_field(resource result [, int field_offset])mysql_connect("localhost", "username", "password");mysql_select_db("MyDatabase");$query = "select * from MyTable";$result = mysql_query($query);$fields = mysql_num_fields($result);for($count = 0; $count < $fieds; $count++) { $field = mysql_fetch_field($result, $count); echo "<p>$field->name $field->type ($field->max_length) </p>";}
返回的对象共有12个对象属性:name: 字段名table: 字段所在的表max_length: 字段的最大长度not_null: 如果字段不能为null,则为1,否则0primary_key: 如果字段为主键,则为1,否则0unique_key: 如果字段是唯一键,则为1, 否则0multiple_key: 如果字段为非唯一,则为1,否则0numeric: 如果字段为数值则为1,否则0blob: 如果字段为BLOB则为1,否则为0type: 字段的数据类型unsigned: 如果字段为无符号数则为1,否则为0zerofill: 如果字段为“零填充”则为1, 否则为0获取
查询的字段数
mysql_num_fields()
integer mysql_num_fields (resource result_set)$query = "select id, name from MyTable order by name";$result = mysql_query($query);echo "这个
查询的字段数是:".mysql_num_fields($result)."<br />";
返回
查询result_set中的字段数获取指定表的所有字段的字段名
mysql_list_fields()
resource mysql_list_fields (string database_name, string table_name [, resource link_id])$fields = mysql_list_fields("MyDatabase", "MyTable");echo "数据库MyDatabase中表MyTable的字段数: ".mysql_num_fields($fields)."<br />";
获取指定的字段选项
mysql_field_flags()
string mysql_field_flags (resource result_set, integer field_offset)
获取指定的字段的最大长度
mysql_field_len()
integer mysql_field_len (resource result_set, integer field_offset)$query = "select name from MyTable";$result = mysql_query($query);$row = mysql_fetch_row($result);echo mysql_field_len($result, 0)."<br />";
如果mysql_field_len($reseult, 0) = 16777215那么numer_format(mysql_field_len($result))等于16,777,215获取字段名
mysql_field_name()
string mysql_field_name (resource result_set, int field_offset)$query = "select id as PKID, name from MyTable order by name";$result = mysql_query($query);$row = mysql_fetch_row($result);echo mysql_field_name($result, 0); // Result: PKID
获取字段类型
mysql_field_type()
string mysql_field_type (resource result_set, int field_offset)$query = "select id, name from MyTable order by name";$result = mysql_query($query);$row = mysql_fetch_row($result);echo mysql_field_type($result, 0); // Result: int
获取字段所在表名
mysql_field_table()
string mysql_field_table (resource result_set, int field_offset)$query