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

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

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

§@ªÌ¡GÀH·Q OSO¶ø¯Á (9) string mysql_error(int [link_id]);
¹ï©óµ¹©wªº³s±µ¡Aªð¦^§t¦³³Ìªñªð¦^ª¬ºAªº»PMySQL¬ÛÃöªº¨ç¼Æªº¿ù»~®ø®§¤å¦r¦ê¡CªÅ­È·N¨ýµÛ¥¼¥X²{¿ù»~¡C

<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
print("Connected successfully");
$query="SELECT * FROM president";
$result=mysql_query($query) or die("query failed,error message=".mysql_error());
?>

(10)array mysql_fetch_array(int result, int [result_typ]);
¥»¨ç¦¡¥Î¨Ó±N¬d¸ßµ²ªG result ©î¨ì°}¦CÅܼƤ¤¡C­Y result ¨S¦³¸ê®Æ¡A«h¶Ç¦^ false ­È¡C¦Ó¥»¨ç¦¡¥i¥H»¡¬O mysql_fetch_row() ªº¥[±j¨ç¦¡¡A°£¥i¥H±N¶Ç¦^¦C¤Î¼Æ¦r¯Á¤Þ©ñ¤J°}¦C¤§¥~¡AÁÙ¥i¥H±N¤å¦r¯Á¤Þ©ñ¤J°}¦C¤¤¡C­Y¬O¦n´X­Ó¶Ç¦^Äæ¦ì³£¬O¬Û¦Pªº¤å¦r¦WºÙ¡A«h³Ì«á¤@­Ó¸m¤JªºÄæ¦ì¦³®Ä¡A¸Ñ¨M¤èªk¬O¨Ï¥Î¼Æ¦r¯Á¤Þ©ÎªÌ¬°³o¨Ç¦P¦WªºÄæ¦ì (column) ¨ú§O¦W (alias)¡C­È±oª`·Nªº¬O¨Ï¥Î¥»¨ç¦¡ªº³B²z³t«×¨ä¹ê¤£·|¤ñmysql_fetch_row() ¨ç¦¡ºC¡A­n¥Î­þ­Ó¨ç¦¡ÁÙ¬O¬Ý¨Ï¥Îªº»Ý¨D¨M©w¡C°Ñ¼Æ result_typ ¬O¤@­Ó±`¼Æ­È¡A¦³¥H¤U´XºØ±`¼Æ MYSQL_ASSOC¡BMYSQL_NUM »P MYSQL_BOTH¡C
¨Ï¥Î½d¨Ò


<?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_array($result))
{
printf("%s %s<BR>
",$row[0],$row[1]);
printf("%s %s<BR>
",$row["last_name"],$row["first_name"]);
}
mysql_free_result($result);

?>


(11) object mysql_fetch_field(int result [,int col_num]);
ªð¦^µ²ªG¶°¤¤µ¹©w¦Cªº¬ÛÃö¤¸¸ê®Æ°T®§¡A¦pªG¨S¦³³o¼Ëªº¦C¡A«hªð¦^°²¡C¦pªG¬Ù²¤col_num¡A«h¹ïmysql_fetch_field()ªº«áÄ~½Õ¥Îªð¦^µ²ªG¶°«áÄò¦Cªº°T®§¡C¦pªG¤£¦A¦³³Ñ¾lªº¦C¡C«hªð¦^­È¬°°²¡C¦pªG«ü©w¤Fcol_num¡A«h¨ä¨ú­È½d³ò¬°0¨ìmysql_num_fields()-1¡C¦b¦¹±¡ªp¤U¡Amysql_num_fields()ªð¦^µ¹©w¦Cªº¬ÛÃö°T®§¡A¦pªGcol_num¶W¥X½d³ò¡Aªð¦^°²¡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 * 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);
$meta=mysql_fetch_field($result);
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>
");
}
?>

(12) array mysql_fetch_lengths(int result);
¥»¨ç¦¡±N mysql_fetch_row() ³B²z¹Lªº³Ì«á¤@¦C¸ê®Æªº¦UÄæ¦ì¸ê®Æ³Ì¤jªø«×©ñ¦b°}¦CÅܼƤ§¤¤¡C­Y°õ¦æ¥¢±Ñ«h¶Ç¦^ false ­È¡C¶Ç¦^°}¦Cªº²Ä¤@µ§¸ê®Æ¯Á¤Þ­È¬O 0¡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 * FROM president" or die("Query failed");
$row_num=0;
while(mysql_fetch_row($result))
{
++$row_num;
printf("Lengths of values in row %d:<BR>
",$row_num);
$len=mysql_fetch_lengths($result);
if(!$len)
{
print("No information available<BR>
");
break;
}
print("<PRE>
");
for($i=0;$i<mysql_num_fields($result);$i++)
printf("Column %d: %s
",$i,$len[$i]);
print("</PRE>
");
}
?>
­Ó¤Hñ¦W@

        ÀR«ä¦Û¦b : ¤@¥y·Å·xªº¸Ü¡A´N¹³©¹§O¤H¨­¤WÅx­»¤ô¡A¦Û¤v·|ªg¨ì¨â¤Tºw¡C
ªð¦^¦Cªí ¤W¤@¥DÃD