bsp; echo("Name: $name ($id) <br />");}
函数从result_set中获取整个数据行,将值放在一个索引数组中。通常会结使list()函数使用获取和显示数据
mysql_fetch_array()
array mysql_fetch_array (resource result_set [, int result_type])$query = "select id, name from MyTable order by name";$result = mysql_query($query);while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = $row["id"]; $name = $row["name"]; echo "Name: $name ($id) <br />";}
result_type的值有:MYSQL_ASSOC: 字段名表示键,字段内容为值MYSQL_NUM: 数值索引数组,操作与mysql_fetch_ros()函数一样MYSQL_BOTH: 即作为关联数组又作为数值索引数组返回。result_type的默认值。获取和显示数据
mysql_fetch_assoc()
array mysql_fetch_assoc (resource result_set)相当于调用 mysql_fetch_array(resource, MYSQL_ASSOC);
获取和显示数据
mysql_fetch_object()
object mysql_fetch_object(resource result_set)$query = "select id, name from MyTable order by name";while ($row = mysql_fetch_object($result)) { $id = $row->id; $name = $row->name; echo "Name: $name ($id) <br />";}
在操作上与mysql_fetch_array()相同所选择的记录
mysql_num_rows()
int mysql_num_rows(resource result_set)#query = "select id, name from MyTable where id > 65";$result = mysql_query($query);echo "有".mysql_num_rows($result)."条记录的ID大于65";
只在确定select
查询所获取的记录数时才有用。受影响的记录
mysql_affected_rows()
int mysql_affected_rows([resource link_id])$query = "update MyTable set name='CheneyFu' where id>=5";$result = mysql_query($query);echo "ID大于等于5的名称被更新了的记录数:".mysql_affected_rows();
该函数获取受INSERT,UPDATE或DELETE更新语句影响的行数获取数据库列表信息
mysql_list_dbs()
resource mysql_list_dbs([resource link_id])mysql_connect("localhost", "username", "password");$dbs = mysql_list_dbs();echo "Databases: <br />";while (list($db) = mysql_fetch_rows($dbs)) { echo "$db <br />";}
获取数据库名
mysql_db_name()
string mysql_db_name(resource result_set, integer index)
该函数获取在mysql_list_dbs()所返回result_set中位于指定index索引的数据库名获取数据库表列表
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 <br />";}
该函数获取database中所有表的表名获取数据库表名
mysql_tablename()
string mysql_tablename(resource result_set, integer index)mysql_connect("localhost", "username", "password");$tables = mysql_list_tables("MyDatabase");$