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

[±Ð¾Ç] (PHP+IIS+MsSQL±Ð¾Ç²Ä31½g) »{ÃÑDML«ü¥O ¤U½g

[±Ð¾Ç] (PHP+IIS+MsSQL±Ð¾Ç²Ä31½g) »{ÃÑDML«ü¥O ¤U½g

Delete§R°£¸ê®Æ
·í§Ú­Ì¨Ï¥ÎRecordset¤¸¥óªºDelete¤èªk§R°£¸ê®Æ¿ý®É¡A¥u¯à¤@µ§¤@µ§ºCºCªº§R°£¡A¦pªG³z¹LSQLªºDelete«ü¥O«h¥i¤@¦¸§R°£¦hµ§¸ê®Æ¡C
¥H¤U¬°Delete«ü¥Oªº°ò¥»»yªk¡G
Delete«ü¥O±Ô­z®æ¦¡
  1. Delete From ¸ê®Æªí¦W Where ±ø¥ó¦¡
½Æ»s¥N½X
¨Ò¦p¡G§R°£¡u¦¨ÁZ³æ¡v¸ê®Æªí¤¤¥þ³¡¡u°ê¤å¡v¤À¼Æ¤p©ó60¤Àªº¦P¾Ç¸ê®Æ¡G
  1. Delete Form ¦¨ÁZ³æ Where °ê¤å < 60
½Æ»s¥N½X
©ÎªÌ¡A§R°£¡u¦¨ÁZ³æ¡v¸ê®Æªí¤¤¥þ³¡¡u¼Æ¾Ç¡v¤À¼Æ¤¶©ó80¨ì60¤Àªº¦P¾Ç¸ê®Æ¡G
  1. Delete Form ¦¨ÁZ³æ Where ¼Æ¾Ç Between 60 And 80
½Æ»s¥N½X
¯S§O­È±o¤@´£ªº¬O¡G¦pªG¨S¦³¼¶¼gWhere«ü¥O±Ô­z¡A«h·|±N¸ê®Æªí¤ºªº¥þ³¡¸ê®Æ¿ý³£§R°£±¼¡G
  1. Delete Form ¦¨ÁZ³æ
½Æ»s¥N½X
¤£¹L¡AÁöµM¬O±N¸ê®Æªí¤ºªº¸ê®Æ¥þ³¡§R°£¡A¦ý¬O¡A¸ê®Æªí¥»¨­ÁÙ¬O¦s¦bªº¡A¥u¬O¸Ì­±¨S¦³¸ê®Æ¦Ó¦¨¬°ªÅªº¸ê®Æªí¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

Update Set ­×§ï¸ê®Æ
¤£ºÞ¬O³æµ§¸ê®Æªº­×§ï¡A©Î¬O¦hµ§¸ê®Æªº­×§ï¡A¬Ò¥i¨Ï¥ÎUpdate Set«ü¥O±Ô­z¡A¨Ò¦p¡G¦Ñ®v¤jµo·O´d¡A¨M©w±N¦P¾Çªº°ê¤å¦Ò¸Õ¦¨ÁZ¥þ³¡³£¥[10¤À¡A¨º»ò¥i¥H¨Ï¥ÎUpdate Set«ü¥O¨Ó¤@¦¸­×¥¿¦hµ§¸ê®Æ¡AUpdate Set«ü¥O±Ô­zªº®æ¦¡¦p¤U¡G
­×§ï¸ê®Æ
  1. Update ¸ê®Æªí¦W Set Äæ¦ì­È¹Bºâ¦¡
½Æ»s¥N½X
¬°¥þ³¡¦P¾Çªº°ê¤å¦¨ÁZ¥[10¤À¡G
  1. Update ¦¨ÁZ³æ Set °ê¤å = °ê¤å + 10
½Æ»s¥N½X
¦pªG­n­×§ï¸ê®ÆªºÄæ¦ì¤£¥u¤@­Ó¡A«h¥i±N¦h­ÓÄæ¦ìªº¸ê®Æ§ó°Ê¹Bºâ¦¡¦ê±µ¦b¡uSet¡v¤§«á¡A¨Ò¦p¡G¬°¥þ³¡¦P¾Çªº°ê¤å¦¨ÁZ¥[10¤À¡A­^¤å¤À¼Æ¥[5¤À¡G
  1. Update ¦¨ÁZ³æ Set °ê¤å = °ê¤å + 10, ­^¤å = ­^¤å + 5
½Æ»s¥N½X
¤W¨â­Ó½d¨Ò±Ô­z¬O±N¥þ³¡ªº¸ê®Æ¿ýÄæ¦ì¸ê®Æ³£¥[¥H­×§ï¡A§Ú­Ì¤]¥i¥H¥[¤W¦³±ø¥óªºWhere«ü¥O±Ô­z¨Ó°µ¦³±ø¥óªº¸ê®Æ­×§ï¡A¨Ò¦p¡G¬°°ê¤å¦¨ÁZ¤¶©ó59¨ì50¤À¤§¶¡ªº¦P¾Ç¡A±N¨ä°ê¤å¦¨ÁZª½±µ´£¤É¬°60¤À¡G
  1. Update ¦¨ÁZ³æ Set °ê¤å = 60 Where °ê¤å Between 59 And 50
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

Select Into ·s¼W¸ê®Æªí
¦p¦ó±N¿z¿ï¥X¨Óªº¸ê®Æ¿ý¦s©ñ¨ì¤@­Ó·sªº¸ê®Æªí¤º¡]¸Ó¸ê®Æªí©|¥¼¦s¦b©ó¸ê®Æ®w¤¤¡^¡H¨Ï¥ÎInsert Into«ü¥O¬OÅK©w¤£¦æªº¡A¦]¬°Insert Into«ü¥O¥u¯à±N¸ê®Æ¦s¤J¡u¤w¸g¡v¦s¦bªº¸ê®Æªí¤º¡C¦pªG­n±N¸ê®Æ¦s¤J¤@­Ó©|¥¼¦s¦bªº¸ê®Æªí¤¤¡A§Ú­Ì¥i¥H¨Ï¥ÎSelect Into«ü¥O¡A·í§Ú­Ì¨Ï¥ÎSelect Into«ü¥O±N¸ê®Æ¦s¤J¸ê®Æªí¤§«e¡ASelect Into«ü¥O·|¥ý¦b¸ê®Æ®w¤¤«Ø¥ß¤@­Ó·sªº¸ê®Æªí«á¡A¦A±N¸ê®Æ¦s©ñ¶i¥h¡C

Select Into«ü¥O¦³¤TºØ¥Îªk¡G

·s¼W¸ê®Æªí¨Ã·s¼W¤@µ§¸ê®Æ¿ý
·s¼W¸ê®Æ¿ý
  1. Select ¡¥Äæ¦ì­È¡¦ As ¡¥Äæ¦ì¦W¡¦ Into ·s¸ê®Æªí¦W
½Æ»s¥N½X
¨Ò¦p¡G·s¼W¤@­Ó¦W¬°¡u´ú¸Õ¡vªº¸ê®Æªí¡A¨Ã©ó¸ê®Æªí¤º·s¼W¤@µ§Äæ¦ì¦WºÙ¬°¡u©m¦W¡v¡AÄæ¦ì­È¬°¡u·¨¤p»x¡v¡BÄæ¦ì¦WºÙ¬°¡umail¡v¡AÄæ¦ì­È¬°¡u[email protected]¡vªº¸ê®Æ¿ý¡A«h¨ä«ü¥O±Ô­z¦p¤U¡G
  1. Select ¡¥·¨¤p»x¡¦ As ©m¦W,¡¦[email protected]¡¦ As mail Into ´ú¸Õ
½Æ»s¥N½X
°õ¦æ¤W¦C«ü¥O±Ô­z«á¡A´N·|¦b¸ê®Æ®w¤¤·s¼W¤@­Ó¡u´ú¸Õ¡v¸ê®Æªí¡A¸ê®Æªí¤º¨Ã¦s¦³¤@µ§¸ê®Æ¡G
  1. <?
  2.     $conn = mssql_connect("127.0.0.1", "sa", "12345");
  3.     if(@mssql_select_db("LEAVE", $conn))
  4.      {
  5.       //¸ê®Æ®w¦s¦b,«Ø¥ßSQL©R¥O¦r¦ê
  6.     $SQL="Select '·¨¤p»x' As ©m¦W,'[email protected]' As mail Into ´ú¸Õ";
  7.       //±N¦^¶Çµ²ªG¦s©ñ©óÅܼƤ¤
  8.       $datalist=mssql_query($SQL);
  9.       //¨ú±oÄæ¦ì¼Æ¶q
  10.       $fieldnum=mssql_num_fields($datalist);
  11.      }
  12.     else
  13.      {
  14.       echo "¸ê®Æ®w¤£¦s¦b";
  15.      }
  16. ?>
½Æ»s¥N½X
ª`·N¡G¦pªG«ü©w·s¼Wªº¸ê®Æªí¦WºÙ¡A¬O¤w¸g¦s¦b©ó¸ê®Æ®wªº¸ê®Æªí¦WºÙ¡A«hSelect Into«ü¥O±Ô­z´N·|°õ¦æ¥¢±Ñ¡A¨Ò¦p¡G²Ä¤@¦¸°õ¦æ½d¨Òex09_06.php«á¡A¡u´ú¸Õ¡v¬O¤@­Ó¦s¦b©ó¸ê®Æ®w¤ºªº¸ê®Æªí¡A¦Ó§Ú­Ì¨Ï¥ÎSelect Into«ü¥O±Ô­z®É¡A«o¤S±N·s¼Wªº¸ê®Æªí¦WºÙ©w¬°¡u´ú¸Õ¡v¡A«h±z±N·|Àò±o¤U¹Ïªº¿ù»~°T®§¡G



½Æ»s¸ê®Æªí
±N¤w¸g¦s¦bªº¸ê®Æªí½Æ»s¤@¥÷¡A¨Ã±N¸ê®Æ¦s¤J·s«Øªº¸ê®Æªí¤º¡G
½Æ»s¸ê®Æªí
  1. Select ¡¯ From ¸ê®Æªí¦W Into ·s¸ê®Æªí¦W
½Æ»s¥N½X
¨Ò¦p¡G¬°¡u¦¨ÁZ³æ¡v¸ê®Æªí«Ø¥ß¤@­Ó³Æ¤À¸ê®Æªí¡u¦¨ÁZ³æ°Æ¥»¡v¡G
(¸`¿ý)
  1. //¸ê®Æ®w¦s¦b,«Ø¥ßSQL©R¥O¦r¦ê
  2.       $SQL="Select * From ¦¨ÁZ³æ Into ¦¨ÁZ³æ°Æ¥»";
  3.       //±N¦^¶Çµ²ªG¦s©ñ©óÅܼƤ¤
  4.       $datalist=mssql_query($SQL);
  5.       //¨ú±oÄæ¦ì¼Æ¶q
  6.       $fieldnum=mssql_num_fields($datalist);
½Æ»s¥N½X
¿z¿ï¸ê®Æ¨Ã¥t¦s©ó·s¸ê®Æªí
³o¬O³Ì±`¥Îªº¤@ºØSelect Into«ü¥O±Ô­z¡A´N¬Oª½±µ¿z¿ï¤w¦s¦bªº¸ê®Æªí¸ê®Æ¡AµM«á±N¿z¿ï«áªº¸ê®Æ¥t¥~«Ø¥ß¦¨¤@­Ó·sªº¸ê®Æªí¡G
·s¼W¸ê®Æªí
  1. Select ¡¯ Into ·s¸ê®Æªí¦WFrom ¸ê®Æªí Where ±ø¥ó¦¡
½Æ»s¥N½X
¨Ò¦p¡G¿z¿ï¡u¦¨ÁZ³æ¡v¸ê®Æªí¤º°ê¤å¦¨ÁZ¤j©ó90¤Àªº¦P¾Ç¸ê®Æ¡A¦s¤J·s«Øªº¡u°ê¤å¤j©ó90¡v¸ê®Æªí¤º¡G
(¸`¿ý)
  1. //¸ê®Æ®w¦s¦b,«Ø¥ßSQL©R¥O¦r¦ê
  2.       $SQL="Select * Into °ê¤å¤j©ó90 From ¦¨ÁZ³æ Where °ê¤å>90";
  3.       //±N¦^¶Çµ²ªG¦s©ñ©óÅܼƤ¤
  4.       $datalist=mssql_query($SQL);
  5.       //¨ú±oÄæ¦ì¼Æ¶q
  6.       $fieldnum=mssql_num_fields($datalist);
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

Insert Into ·s¼W¸ê®Æ
Insert Into«ü¥O¦³¨âºØ¥Îªk¡G¤@ºØ¬O·s¼W¸ê®Æ¿ý¡A¥t¤@ºØ¬O±N¨ú±oªº¸ê®Æ·s¼W¨ì¥t¤@­Ó¤w¸g¦s¦bªº¸ê®Æªí¤º¡G


·s¼W¸ê®Æ¿ý
¨Ï¥ÎInsert Into«ü¥O·s¼W¸ê®Æ¿ý¨ì¸ê®Æªí¤º¡A¨ä®æ¦¡¦p¤U¡G
·s¼W¸ê®Æ¿ý
  1. Insert Into ¸ê®Æªí¦W¡]Äæ¦ì1,Äæ¦ì2,¡K¡^
  2. Values(Äæ¦ì1­È,Äæ¦ì2­È¡K)
½Æ»s¥N½X
­n·s¼W¤@µ§¸ê®Æ¨ì¸ê®Æªí¤¤¡A¥²¶·¥ý«ü©w¦UÄæ¦ìªº¦WºÙ¡A¦A±NÄæ¦ì­È³v¤@ªº«ü©wµ¹¬Û¹ïÀ³ªºÄæ¦ì¡G
1.png


°²­Y¡A¦bValues(¡K)¤¤ªºÄæ¦ì­È¶¶§Ç»P­ì©l¸ê®Æªí¤¤©Ò©w¸qªºÄæ¦ì¶¶§Ç§¹¥þ¬Û¦P¡A¨Ã¥B¡A¦bValues(¡K)¤¤©Ò¶ñ¤JªºÄæ¦ì­È¼Æ¶q»P­ì©l¸ê®Æªí¤¤ªºÄæ¦ì¼Æ¥Ø¬O¬Û¦Pªº¡A«h§Ú­Ì¥i¥H¤£¥²«ü©wÄæ¦ì¦WºÙ¡A¨Ò¦p¡G
  1. Insert Into ¦¨ÁZ³æ Values(900712,¡¦·¨¤p»x¡¦,90,80,92)
½Æ»s¥N½X
2.png


·s¼W¸ê®Æ¨ì¤w¦s¦bªº¸ê®Æªí
±NSelect«ü¥O©Ò¿ï¨úªº¸ê®Æ¿ý·s¼W¨ì¥t¤@­Ó¤w¸g¦s¦bªº¸ê®Æªí¤º¡A¥i¨Ï¥Î¤U¦C®æ¦¡ªºInsert Into®æ¦¡±Ô­z¡G
·s¼W¸ê®Æ¿ý¨ì¸ê®Æªí
  1. Insert Into ¸ê®Æªí¦W ¡]Äæ¦ì1,Äæ¦ì2,¡K¡^Select¡K  
½Æ»s¥N½X
ª`·N¡G¤W¦¡¤¤ªº¡u¸ê®Æªí¦W¡v¬O«ü­ì¥»´N¤w¸g¦s¦bªº¸ê®Æªí¡I

¦pªG¡A¦³¨â­Ó¸ê®ÆªíªºÄæ¦ì®æ¦¡»P¶¶§Ç¤@¼Ò¤@¼Ë¡A¦p¤W¹Ïªº¡u¦¨ÁZ³æ¡v¡B¡u§Úªº¦¨ÁZ³æ¡v¸ê®Æªí¡A¦pªG­n±N¡u¦¨ÁZ³æ¡v¸ê®Æªí¤¤°ê¤å¤À¼Æ¤j©ó90ªº¦P¾Ç¸ê®Æ·s¼W¨ì¡u§Úªº¦¨ÁZ³æ¡v¸ê®Æªí®É¡A¦]¬°¨â­Ó¸ê®ÆªíªºÄæ¦ì¦WºÙ¤Î¶¶§Ç³£¤@¼Ë¡A¨º»ò¦bInsert Into«ü¥O±Ô­z¤¤´N¥i¥H¬Ù²¤«ü©wÄæ¦ì¦WºÙªº±Ô­z¡G
  1. Insert Into §Úªº¦¨ÁZ³æ
  2. Select * From ¦¨ÁZ³æWhere °ê¤å>90
½Æ»s¥N½X
«h¤W¦¡ªº°õ¦æµ²ªG¦p¤U¹Ï¡G



°²­Y¡A¨â­Ó¸ê®ÆªíÄæ¦ì¶¶§Ç¬O¤£¦Pªº¡A¦p¤U¹Ï¤¤ªº¡u¦¨ÁZ³æ¡v¡B¡u§Aªº¦¨ÁZ³æ¡v¸ê®Æªí¡C

¦pªG­n±N¡u¦¨ÁZ³æ¡v¸ê®Æªí¤¤°ê¤å¤À¼Æ¤j©ó90ªº¦P¾Ç¸ê®Æ·s¼W¨ì¡u§Aªº¦¨ÁZ³æ¡v¸ê®Æªí®É¡A´N¥²¶·¤@¤@ªº«ü©wÄæ¦ì¦WºÙ¡G
  1. Insert Into §Aªº¦¨ÁZ³æ¡]¾Ç¸¹, ©m¦W,°ê¤å,­^¤å,¼Æ¾Ç¡^
  2. Select * From ¦¨ÁZ³æWhere °ê¤å>90
½Æ»s¥N½X
¤W¨Òªº°õ¦æµ²ªG¦p¤U¹Ï¡G
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : °ß¨ä´L­«¦Û¤vªº¤H¡A¤~§ó«i©óÁY¤p¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD