直播中
<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("stamp_db") or die("Could not select database");
$query="SELECT last_name,first_name FROM president";
$result=mysql_query($query) or die("Query failed");
while($row=mysql_fetch_object($result))
printf("%s %s<BR>
",$row->last_name,$row->first_name);
mysql_free_result($result);
?>
(14) array mysql_fetch_row(int result);
作為一個數(shù)組返回給定結(jié)果集的下一行,如果沒有更多的行,則返回假。列值可作為數(shù)組元素訪問,在0到mysql_num_fields()-1范圍內(nèi)使用列索引。
<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("stamp_db") or die("Could not select database");
$query="SELECT last_name,first_name FROM president";
$result=mysql_query($query) or die("Query failed");
while($row=mysql_fetch_row($result))
printf("%s %s<BR>
",$row[0],$row[1]);
mysql_free_result($result);
?>
(15) string mysql_field_name(int result, int field_index);
返回結(jié)果集的給定列的名稱。
col_num 的范圍為0到mysql_num_fields()-1.
<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("stamp_db") or die("Could not select database");
$query="SELECT * FROM president";
$result=mysql_query($query) or die("Query failed");
for($i=0;$i<mysql_num_fields($result);$i++)
{
printf("Name of column %d:",$i);
$name=mysql_field_name($result,$i);
if(!$name)
print("No name available<BR>
");
else
print("$name<BR>
");
}
?>
(16) int mysql_field_seek(int result, int field_offset);
為隨后的mysql_fetch_field()調(diào)用設置索引。發(fā)布沒有明確列號的mysql_fetch_field()的下一次調(diào)用,將返回列col_num的信息。如果搜索成功,返回真,否則返回假。
col_num的范圍為0到mysql_num_fields()-1.
<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("stamp_db") or die("Could not select database");
$query="SELECT * FROM president";
$result=mysql_query($query) or die("Query failed");
for($i=0;$i<mysql_num_fields($result);$i++)
{
printf("Information for column %d:<BR>
",$i);
if(!mysql_field_seek($result,$i))
{
print("Cannot seek to colum<BR>
");
continue;
}
$meta=mysql_fetch_field($result,$i);
if(!$meta)
{
print("No information available<BR>
");
continue;
}
print("<PRE>
");
printf("blob: %s
",$meta->blob);
printf("max_length: %s
",$meta->max_length);
printf("multiple_key: %s
",$meta->multiple_key);
printf("name: %s
",$meta->name);
printf("not_null: %s
",$meta->not_null);
printf("numeric: %s
",$meta->numeric);
printf("primary_key: %s
",$meta->primary_key);
printf("table: %s
",$meta->table);
printf("type: %s
",$meta->type);
printf("unique_key: %s
",$meta->unique_key);
printf("unsigned: %s
",$meta->unsigned);
printf("zerofill: %s
",$meta->zerofill);
print("</PRE>
");
}
?>