网络编程
位置:首页>> 网络编程>> 数据库>> PHP中的MYSQL常用函数(3)

PHP中的MYSQL常用函数(3)

 来源:Asp之家 发布时间:2010-09-30 14:49:00 

标签:php,mysql,函数

15、mysql_db_name()-获取数据库名

格式:

string mysql_db_name(resource result_set, integer index)

说明:该函数获取在mysql_list_dbs()所返回result_set中位于指定index索引的数据库名

16、mysql_list_tables()-获取数据库表列表

格式:

resource mysql_list_tables(string database [, resource link_id])

例:

mysql_connect("localhost", "username", "password");

$tables = mysql_list_tables("MyDatabase");

while (list($table) = mysql_fetch_row($tables)) {

echo "$table
";

}

说明:该函数获取database中所有表的表名

17、mysql_tablename()-获取某个数据库表名

格式:

string mysql_tablename(resource result_set, integer index)

例:

mysql_connect("localhost", "username", "password");

$tables = mysql_list_tables("MyDatabase");

$count = -1;

while (++$count < mysql_numrows($tables)) {

echo mysql_tablename($tables, $count)."
";

}

说明:该函数获取mysql_list_tables()所返回result_set中位于指定index索引的表名

18、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);

$counts = mysql_num_fields($result);

for($count = 0; $count < $counts; $count++) {

$field = mysql_fetch_field($result, $count);

echo "

$field->name $field->type ($field->max_length)

";


}

说明:

返回的对象共有12个对象属性:

name: 字段名

table: 字段所在的表

max_length:字段的最大长度

not_null: 如果字段不能为null,则为1,否则0

primary_key: 如果字段为主键,则为1,否则0

unique_key: 如果字段是唯一键,则为1, 否则0

multiple_key: 如果字段为非唯一,则为1,否则0

numeric: 如果字段为数值则为1,否则0

blob: 如果字段为BLOB则为1,否则为0

type: 字段的数据类型

unsigned: 如果字段为无符号数则为1,否则为0

zerofill: 如果字段为“零填充”则为1, 否则为0

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com