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

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

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ªG­nÃö³¬¤@­Ó³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());
?>
­Ó¤Hñ¦W@

·PÁ¤j¤jµL¨pªº¤À¨É¡A
·Q½Ð±Ð¤@­Ó°ÝÃD¡A
¬O§_ªì¾ÇªÌ³£¸Ó§â¤W­±ªº¨ç¼Æ­I°_¨Ó©O??

TOP

ÁÂÁ¤À¨É¡A½Ð°Ý¦³¨S¦³¦n¥Îªº¨ç¼Æ°Ñ¦Òºô¯¸? ­ì¥»·Q¶R¤u¨ã®Ñ¥i¬O²{¦b¦ü¥G³£¨S¦³¦A¥X¤F

TOP

§Ú¤]·Qª¾¹D¦³¨º¨Ç¦n¥Îªº¤u¨ã®Ñ...

TOP

Google ´N¦³¤£¤Ö¡A§Ú¤ñ¸û³ßÅwªº¦³´X­Ó¡G
https://dev.mysql.com/doc/refman/5.7/en/join.html
https://www.w3schools.com/php/php_mysql_select.asp

·f°t PHP ¨ç¼Æ°Ñ¦Òºô­¶¡G
http://php.net/manual/en/class.datetime.php

¤£µM´N¬O¨ì stackoverflow ¬Ý¬Ý§O¤H¨ç¼Æªº¥Îªk¡C

TOP

        ÀR«ä¦Û¦b : ¸Ü¦h¤£¦p¸Ü¤Ö¡A¸Ü¤Ö¤£¦p¸Ü¦n¡C
ªð¦^¦Cªí ¤W¤@¥DÃD