- ©«¤l
- 20
- ¥DÃD
- 18
- ºëµØ
- 0
- ¿n¤À
- 43
- ÂI¦W
- 0
- §@·~¨t²Î
- windows xp
- ³nÅ骩¥»
- Office 2003
- ¾\ŪÅv
- 10
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2011-9-5
- ³Ì«áµn¿ý
- 2011-9-6
|
MySQL¸ê®Æ®w¨ç¼Æ¸Ô¸Ñ(1)
§@ªÌ¡GÀH·Q OSO¶ø¯Á¡]1¡^ int mysql_affected_rows([int link_id]);
¦bµ¹©wªº³s±µ¤¤¡Aªð¦^¥Ñ³ÌªñªºDELETE¡BINSERT¡BREPLACE©ÎªÌUPDATE»y¥y©Ò§@¥Îªº¦æ¼Æ¡C¦pªG¨S¦³¦æ
³Qקï¡A«hmysql_affected_rows()ªð¦^0¡A¦pªG¥X²{¿ù»~¡A«hªð¦^-1¡C
¦bSELECT¬d¸ß¤§«á¡Amysql_affected_rows()ªð¦^©Ò¿ï¾Üªº¦æ¼Æ¡C¦ý¤@¯ë¬O»PSELECT»y¥y¤@¹D¨Ï¥Î
mysql_num_rows().
¨Ï¥Î½d¨Ò¡G
<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("samp_db") or die("Could not select database");
$query="INSERT INTO
member(last_name,first_name,expiration)"."VALUES('Brown','Marcia','2002-6-3')";
$result=mysql_query($query) or die("Query failed");
printf("%d row%s insertedn",mysql_affected_rows(),mysql_affected_rows()==1?" ":"s");
?>
¡]2¡^ int mysql_close(int[link_id]);
Ãö³¬¥Ñlink_id¼ÐÃѪº»PMySQLªA°È¾¹ªº³s±µ¡C¦pªG¨S¦³«ü©w³s±µ¡A«hmysql_close()Ãö³¬³Ìªñ¥´¶}ªº³s
±µ¡C¦pªG¦¨¥\¡A«hmysql_close()ªð¦^¯u¡A¥¢±Ñ«hªð¦^°²¡C¹ï¥Ñmysql_pconnect()¥´¶}ªº¥Ã¤[³s±µ¡A
mysql_close()©¿²¤¬ÛÀ³ªºÃö³¬½Ð¨D¡A¥u¬Oªð¦^È¡C¦pªGnÃö³¬¤@Ó³s±µ¡A´NÀ³¸Ó¥Îmysql_connect()¦Ó¤£¬O
mysql_pconnect()¨Ó¥´¶}¥¦¡C
¨Ï¥Î½d¨Ò¡G
<?php
$link=mysql_connect("localhost","sunsoft","suixiang") or die("Could not connect");
print("Connected successfully");
mysql_close($link);
?>
¡]3¡^ int mysql_connect(string [hostname] [:port], string [username], string [password]);
¥»¨ç¦¡«Ø¥ß»P MySQL ¦øªA¾¹ªº³s½u¡C¨ä¤¤©Ò¦³ªº°Ñ¼Æ³£¥i¬Ù²¤¡C·í¨Ï¥Î¥»¨ç¦¡«o¤£¥[¥ô¦ó°Ñ¼Æ®É¡A°Ñ
¼Æ hostname ªº¤º©wȬ° localhost¡B°Ñ¼Æ username ªº¤º©wȬ° PHP °õ¦æ¦æµ{ªº¾Ö¦³ªÌ¡B°Ñ¼Æ password «h
¬°ªÅ¦r¦ê (§Y¨S¦³±K½X)¡C¦Ó°Ñ¼Æ hostname «á±¥i¥H¥[«_¸¹»P°ð¸¹¡A¥Nªí¨Ï¥Î¨ºÓ°ð»P MySQL ³s±µ¡C·íµM¦b
¨Ï¥Î¸ê®Æ®w®É¡A¦ÂI¨Ï¥Î mysql_close() ±N³s½uÃö±¼¥i¥H¸`¬Ù¸ê·½¡C
¨Ï¥Î½d¨Ò
³o¬O¤@¦ì¥¼¨ã¦Wºô¤Í´£¨Ñªº½d¨Ò (18-Feb-1999)
<?php
$dbh = mysql_connect('localhost:3306','mcclain','standard');
mysql_select_db('admreqs');
$query = "insert into requests(date, request, email, priority,status) values
(NOW(),'$description', '$email', '$priority', 'NEW')";
$res = mysql_query($query, $dbh);
$query = "select max(id) from requests";
$res = mysql_query($query, $dbh);
$err = mysql_error();
if($err){
echo "µo¥Í¿ù»~¡A½Ð³qª¾<a href=mailto:[email protected]>¯¸ªø</a>";
}
$row = mysql_fetch_row($res);
echo "¥¼¨Ó±z¨Ï¥Îªº¸¹½X¬°: ".$row[0];
?>
¡]4¡^ int mysql_create_db(string db_name [, int link_id]);
§i¶D¥Ñlink_id¼ÐÃѪºMySQLªA°È¾¹¥Îµ¹©wªº¦WºÙ¨Ó·s¼W¸ê®Æ®w¡C¦pªG¸ê®Æ®w·s¼W¦¨¥\¡A«hªð¦^¯u¡F¦p
ªG¥X²{¿ù»~¡A«hªð¦^°²¡C¥²¶·¦b¸ê®Æ®w¦³·s¼W¥¦ªºCREATEÅv¡C
¥i¯à§Q¥Îmysql_query()¸û§Q¥Îmysql_create_db()µo§GCREATE DATABASE »y¥y§ó¬°¾A¦X¡C
<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang"); or die("Could not connect");
if(mysql_create_db("my_db"))
print("Database created successfullyn");
else
print("Error creating database:%sn",mysql_error());
?> |
|