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

7-2 PHP»PMySQLªº³sµ²

7-2 PHP»PMySQLªº³sµ²

7-2   PHP»PMySQLªº³sµ²
¤W£¸¸`¯S§O»¡©ú¡G­n¹ï¸ê®Æ®w¦s¨ú¸ê®Æ¥²¶·¥ý¶i¦æ¸ê®Æ®wªº³sµ²ªº°Ê§@¡A­Y­n¦s¨úMySQLªº¸ê®Æ¥ç¤£¨Ò¥~¡A­n§Q¥ÎPHP¹ïMySQL Server¶i¦æ³sµ²°Ê§@¥i¨Ï¥ÎPHPªºMySQL¸ê®Æ®w¨ç¼Æ¡G¡umysql_connect()¡v©Î¡umysql_pconnect()¡v¨ç¼Æ¡C
mysql_connect() ¨ç¼Æ
  1. resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]])
½Æ»s¥N½X
·í¸ê®Æ®w³sµ²¦¨¥\«h¦^¶Ç³s½uªº½s¸¹¡A­Y³s½u¥¢±Ñ«h¦^¶Ç0¡]False¡^¡C

mysql_pconnect() ¨ç¼Æ
  1. resource mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]])
½Æ»s¥N½X
·í¸ê®Æ®w³sµ²¦¨¥\«h¦^¶Ç³s½uªº½s¸¹¡A­Y³s½u¥¢±Ñ«h¦^¶Ç0¡]False¡^¡C

mysql_close() ¨ç¼Æ
  1. bool mysql_close ( [resource link_identifier])
½Æ»s¥N½X
mysql_connect()¨ç¼Æ¬O¼È®É©Êªº³s½u¡A¨C¦¸³sµ²³£·|¨Ï¸ê®Æ®w²£¥Í¤@­Ó·sªº³s½uªÌ¡A©Ò¥H¨C¦¸³sµ²«á¡A·í¤£»Ý­n¦¹³s½u®É´N¸Ó¥Î¡umysql _close()¡v¨ç¼ÆÃö³¬³sµ²¡A¤£µM±zªº¸ê®Æ®w©Î¦øªA¾¹­t¾á¤Ó­«´N·|¥X°ÝÃD¡A¤£¹L¡A·íPHPµ{¦¡°õ¦æ§¹²¦«á¡A«h»P¸ê®Æ®wªº³sµ²·|¦Û°ÊÃö³¬¡A¦]¦¹¥i¤£¥²¦A§Q¥Î¡umysql _close()¡v¨ç¼ÆÃö³¬³sµ²¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

mysql _pconnect()¨ç¼Æ¬O¿W¥e©Êªº³s½u¡A·í»P¸ê®Æ®w©¹ªðªº¸ê®Æ¤j®É¡A¥i¨Ï¥Î¦¹¨ç¼Æ³sµ²¸ê®Æ®w¡A§Y¨ÏPHPµ{¦¡¤w¸g°õ¦æ§¹²¦¡A¦¹³s½u¨ÌµM¦s¦b¡A­Y¦¹³s½u¼È®É¨S¦³¥Î¨ì«h³s½u¶i¤J¡u¥ð¯v¡]sleep¡^¡vª¬ºA¡A·í§Ú­Ì¦A¦¸¥Hmysql _pconnect()¨ç¼Æ³s½u®É¡A¥i¥Hª½±µ¨Ï¥Î¥ý«e¥Î§¹¶¢¸mªº³s½u¡A¦Ó¤£¥²­««Ø¡C


¥»®Ñ½d¨Ò­Y»Ý»PMySQL Server«Ø¥ß³sµ²¡A¬Ò¨Ï¥Îmysql_connect()¨ç¼Æ¡C
³z¹Lmysql_connect()¨ç¼Æ»PMySQL Server«Ø¥ß³sµ²¡A¦³¥²­nªº¤T­Ó°Ñ¼Æ¡G¡u¥D¾÷¡v¡B¡u±b¸¹¡v»P¡u±K½X¡v¡G
  1. mysql_connect ("¥D¾÷¦WºÙ", "±b¸¹", "±K½X") ;
½Æ»s¥N½X
¨Ò¦p¡G
  1. mysql_connect ("localhost", "root", "12345a") ;
½Æ»s¥N½X

  • ¥D¾÷¦WºÙ¡G·íPHPµ{¦¡»PMySQL Server¬O¦ì©ó¦P¤@³¡¾÷¾¹®É¶ñ¼g¡ulocalhost¡vªí¥Ü¥»¾÷¡A­YPHPµ{¦¡»PMySQL Server¤£¦b¦P¤@³¡¾÷¾¹¡A«h¶ñ¤JMySQL Server©Ò¦bªº¾÷¾¹¦ì§}¡]IP¡^¡C
  • ±b¸¹¡G¦³Åvµn¤JMySQL Serverªº¨Ï¥ÎªÌ±b¸¹¡C
  • ±K½X¡G¦³Åvµn¤JMySQL Serverªº¨Ï¥ÎªÌ±K½X¡C


¹ê¨Ò¡G¡]½d¨Òex07_04.php¡^
  1. <?
  2. $userName="root"; //±b¸¹
  3. $password="12345";  //±K½X
  4. $hostName="localHost"; //¥D¾÷(Server)¦WºÙ

  5. //«Ø¥ß¸ê®Æ³sµ²
  6. if (!(@ $link=mysql_connect($hostName, $userName, $password)))
  7. {
  8. printf("<Br> ³sµ²¥D¾÷ %s µo¥Í¿ù»~ <br>", $hostName);
  9. exit();
  10. }
  11. else
  12. {
  13. printf("<Br> ³sµ²¥D¾÷ %s ¦¨¥\ <br>", $hostName);
  14. exit();
  15. }
  16. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ¤ß¤¤±`¦sµ½¸Ñ¡B¥]®e¡B·P«ä¡Bª¾¨¬¡B±¤ºÖ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD