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

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

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

§@ªÌ¡GÀH·Q OSO¶ø¯Á(5) int mysql_data_seek(int result_id, int row_num);

¥Ñ SELECT¬d¸ßªð¦^ªº¨C­Óµ²ªG¶°³£¦³¤@­Ó¦æ¹C¼Ð¡A«ü¥Ü¤U¤@­Ó´£¨ú¦æªº¨ç¼Æ(mysql_fetch_array()¡B mysql_fetch_object()©ÎªÌmysql_fetch_row())½Õ¥Î±Nªð¦^­þ¤@¦æ¡Cmysql_data_seek()±Nµ¹©wµ²ªG¶°ªº«ü°w³]¸m¨ìµ¹©wªº¦æ¡C¦æ¸¹ªº½d³ò¬°0¨ìmysql_num_rows()-1¡C¦pªG¦æ¸¹¦Xªk¡A«hmysql_data_seek()ªð¦^¯u¡A§_«hªð¦^°²¡C
<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("samp_db") or die("Could not select database");
$query="SELECT last_name,first_name FROM president");
$result=mysql_query($query) or die("Query failed");
for($i=mysql_num_rows($result)-1;$i>=0;$i-)
{
if(!mysql_data_seek($result,$i);
{
printf("Cannot seek to row %dn",$i);
continue;
}
if(!$row=mysql_fetch_object($result)))
continue;
printf("%d %s<BR>n",$row->last_name,$row->first_name);
}
mysql_free_result($result);
?>


(6) int mysql_db_query(string db_name, string query [, int link_id]);
mysql_db_query()°£¤F´£¨ú¤@­ÓÃB¥~ªº¸ê®Æ®w¦WºÙ°Ñ¼Æ¡A¨Ã¦b°õ¦æ¬d¸ß¤§«e¨Ï¥¦¦¨¬°¯Ê¬Ùªº¸ê®Æ®w¬°¡A»Pmysql_query()Ãþ¦ü¡C

<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
print("Connected successfully");
$query="SELECT * FROM president";
$result=mysql_db_query("samp_db",$query) or die("Query failed");
?>


(7) int mysql_drop_db(string db_name, int [link_id]);
§i¶D¥Ñlink_id¼ÐÃѪºMySQLªA°È¾¹¥Îµ¹©wªº¦WºÙ¨Ó§R°£¸ê®Æ®w¡C¦pªG¸ê®Æ®w§R°£¦¨¥\¡A«hªð¦^¯u¡F¦pªG¥X²{¿ù»~¡A«hªð¦^°²¡C¥²¶·¦³¹ï¸ê®Æ®w¶i¦æ§R°£ªºDROPÅv­­¡C
­n¤p¤ß³o­Ó¨ç¼Æ¡F¦pªG§R°£¸ê®Æ®w¡A¥¦´N¤£¦s¦b¤F¡A¥B¤£¯à«ì´_¡C
¨Ï¥Îmysql_query()¸û¨Ï¥Îmysql_drop_db()µo§GDROP DATABASE »y¥y§ó¬°¾A¦X¡C
<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
if(mysql_drop_db("my_db"))
print("Database dropped successfullyn");
else
printf("Error dropping database:%sn",mysql_error());
?>


(8) int mysql_errno(int [link_id]);

¹ï©óµ¹©wªº³s±µ¡Aªð¦^§t¦³³Ìªñªð¦^ª¬ºAªº»PMySQL¬ÛÃöªº¨ç¼Æªº¿ù»~¸¹¡C¹s­È·N¨ýµÛ¥¼¥X²{¿ù»~¡C

¨Ï¥Î½d¨Ò

<?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 code=".mysql_errno());
?>
­Ó¤Hñ¦W@

        ÀR«ä¦Û¦b : ¬°¦Û¤v§äÂǤfªº¤H¥Ã»·¤£·|¶i¨B¡C
ªð¦^¦Cªí ¤W¤@¥DÃD