ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

MySQL¸ê®Æ®w¨ç¼Æ¸Ô¸Ñ(4)

MySQL¸ê®Æ®w¨ç¼Æ¸Ô¸Ñ(4)

§@ªÌ¡GÀH·Q OSO¶ø¯Á (13) object mysql_fetch_object(int result_id [, int result_typ]);
¥»¨ç¦¡¥Î¨Ó±N¬d¸ßµ²ªG result ©î¨ìª«¥óÅܼƤ¤¡C¨Ï¥Î¤èªk©M mysql_fetch_array() ´X¥G¬Û¦P¡A¤£¦Pªº¦a¤è¦b©ó¥»¨ç¦¡¶Ç¦^¸ê®Æ¬Oª«¥ó¦Ó¤£¬O°}¦C¡C­Y result ¨S¦³¸ê®Æ¡A«h¶Ç¦^ false ­È¡C¥t¥~­È±oª`·Nªº¦a¤è¬O¡A¨ú¦^ªºª«¥ó¸ê®Æªº¯Á¤Þ¥u¯à¬O¤å¦r¦Ó¤£¯à¥Î¼Æ¦r¡A³o¬O¦]¬°ª«¥óªº¯S©Ê¡Cª«¥ó¸ê®Æªº¯S©Ê¤¤©Ò¦³ªºÄÝ©Ê(property) ¦WºÙ³£¤£¯à¬O¼Æ¦r¡A¦]¦¹¥u¦n¨Ä¨Ä¨Ï¥Î¤å¦r¦r¦ê·í¯Á¤Þ¤F¡C°Ñ¼Æ result_typ¬O¤@­Ó±`¼Æ­È¡A¦³¥H¤U´XºØ±`¼Æ MYSQL_ASSOC¡BMYSQL_NUM »P MYSQL_BOTH¡CÃö©ó³t«×¤è­±¡A¥»¨ç¦¡ªº³B²z³t«×´X¥G©Mmysql_fetch_row() ¤Î mysql_fetch_array() ¤G¨ç¦¡®t¤£¦h¡A­n¥Î­þ­Ó¨ç¦¡ÁÙ¬O¬Ý¨Ï¥Îªº»Ý¨D¨M©w¡C

<?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);
§@¬°¤@­Ó°}¦Cªð¦^µ¹©wµ²ªG¶°ªº¤U¤@¦æ¡A¦pªG¨S¦³§ó¦hªº¦æ¡A«hªð¦^°²¡C¦C­È¥i§@¬°°}¦C¤¸¯À³X°Ý¡A¦b0¨ìmysql_num_fields()-1½d³ò¤º¨Ï¥Î¦C¯Á¤Þ¡C

<?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);
ªð¦^µ²ªG¶°ªºµ¹©w¦Cªº¦WºÙ¡C
col_num ªº½d³ò¬°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);
¬°ÀH«áªºmysql_fetch_field()½Õ¥Î³]¸m¯Á¤Þ¡Cµo§G¨S¦³©ú½T¦C¸¹ªºmysql_fetch_field()ªº¤U¤@¦¸½Õ¥Î¡A±Nªð¦^¦Ccol_numªº°T®§¡C¦pªG·j´M¦¨¥\¡Aªð¦^¯u¡A§_«hªð¦^°²¡C
col_numªº½d³ò¬°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>
");
}
?>
­Ó¤Hñ¦W@

        ÀR«ä¦Û¦b : ¦n¨Æ­n´£±o°_¡A¬O«D­n©ñ±o¤U¡A¦¨´N§O¤H§Y¬O¦¨´N¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD