thinkphpÖÐinɾ³ýÒªÁìµÄʹÓúÍÓ¦Óó¡¾°ÊÇʲô
Ò»¡¢Ê²Ã´ÊÇinɾ³ýÒªÁì
inɾ³ýÒªÁìͨ³£Ê¹ÓÃÒ»¸ö°üÀ¨¶à¸öÖµµÄÊý×é×÷ΪÌõ¼þ£¬ÔÚÊý¾Ý¿âÖÐɾ³ýÇкÏÕâЩÌõ¼þµÄ¶àÌõ¼Í¼¡£ºÃ±ÈÏÂÃæµÄÒ»ÌõSQLÓï¾ä£º
DELETE FROM user WHERE id IN (1, 2, 3, 4, 5);
Óû§±íÖÐidΪ1¡¢2¡¢3¡¢4¡¢5µÄ¼Í¼½«±»´ÓSQLÓï¾äÖÐɾ³ý¡£ÕâÖÖÖðһɾ³ýÒªÁì»ùÓÚSQLÓï¾äµÄÍ·ÄÔ¶øÀ´£¬ËüʹµÃÎÒÃÇÖ´ÐÐÕâÖÖ²Ù×÷Ô½·¢±ã½Ý¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
¶þ¡¢ÔõÑùʹÓÃinɾ³ýÒªÁì
ÔÚThinkPHPÖУ¬inɾ³ýÒªÁìµÄʹÓúÜÊǼòÆÓ£¬Ö»ÐèҪŲÓÃÄ£×ÓµÄdeleteÒªÁ죬²¢´«ÈëÒ»¸ö°üÀ¨¶à¸öÖµµÄÊý×é¼´¿É¡£ÏÂÃæÊÇÒ»¸öʾÀý´úÂ룺
$user = new UserModel();
$ids = array(1, 2, 3, 4, 5);
$result = $user->where(‘id’, ‘in’, $ids)->delete();
ÎÒÃÇÊ×ÏÈʵÀý»¯ÁËÒ»¸öUserModel£¬½«Æ丳¸ø$user±äÁ¿£¬½Ó׎ç˵ÁËÒ»¸ö$idsÊý×飬ÆäÖаüÀ¨¶à¸öidÖµ¡£½Ó×Å£¬ÎÒÃÇŲÓÃÁË$userµÄwhereÒªÁ죬´«ÈëÁË¡¯in¡¯×÷Ϊ½ÏÁ¿·û£¬ÒÔ¼°$idsÊý×飬ÌåÏÖÅÌÎÊÓû§idΪ$idsÊý×éÖеÄí§ÒâÒ»¸öµÄ¼Í¼¡£×îÖÕ£¬ÎÒÃÇʹÓÃÁËdeleteÒªÁ죬ɾ³ýÁËÇкÏÌõ¼þµÄ¼Í¼£¬²¢½«Ð§¹û´æ´¢ÔÚ$result±äÁ¿ÖС£
Èý¡¢inɾ³ýÒªÁìµÄÓ¦Óó¡¾°
inɾ³ýÒªÁìÔÚÐí¶à³¡¾°Ï¶¼ºÜÊÇÓÐÓá£ÀýÈ磬ÎÒÃÇ¿ÉÒÔÔËÓÃinɾ³ýÒªÁ죬ɾ³ýÌض¨·ÖÀàϵÄËùÓÐÎÄÕ£¬Ò²¿ÉÒÔɾ³ý¶à¸öÓû§¡£ÏÂÃæÊÇһЩinɾ³ýÒªÁìµÄ³£¼ûÓ¦Óó¡¾°£º
1.ÅúÁ¿É¾³ýÓû§
¼ÙÉèÎÒÃÇÓÐÒ»¸öÓû§ÖÎÀíϵͳ£¬ÐèҪʵÏÖÅúÁ¿É¾³ý¶à¸öÓû§¡£ÎÒÃÇ¿ÉÒÔʹÓÃinɾ³ýÒªÁìÀ´ÊµÏÖÕâ¸ö¹¦Ð§£¬´úÂëʾÀýÈçÏ£º
$user = new UserModel();
$ids = array(1, 2, 3, 4, 5);
$result = $user->where(‘id’, ‘in’, $ids)->delete();
Õâ¶Î´úÂ뽫ɾ³ýidΪ1¡¢2¡¢3¡¢4¡¢5µÄÓû§¼Í¼¡£
2.ÅúÁ¿É¾³ýÎÄÕÂ
ÈôÊÇÎÒÃÇÐèÒªÒ»´ÎÐÔɾ³ýij¸ö·ÖÀàϵÄËùÓÐÎÄÕ£¬¿ÉÒÔ˼Á¿ÔÚ²©¿ÍϵͳÖÐÌí¼ÓÅúÁ¿É¾³ý¹¦Ð§¡£ÎÒÃÇ¿ÉÒÔʹÓÃinɾ³ýÒªÁìÀ´ÊµÏÖÕâ¸ö¹¦Ð§£¬´úÂëʾÀýÈçÏ£º
$article = new ArticleModel();
$ids = array(21, 22, 23, 24, 25);
$result = $article->where(‘category_id’, 10)->where(‘id’, ‘in’, $ids)->delete();
Õâ¶Î´úÂ뽫ɾ³ý·ÖÀàidΪ10£¬ÇÒidΪ21¡¢22¡¢23¡¢24¡¢25µÄÎÄռͼ¡£
ËÄ¡¢×¢ÖØÊÂÏî
1.inɾ³ýÒªÁìÖ»ÄÜɾ³ýÇкÏij¸öÌõ¼þµÄ¶àÌõ¼Í¼£¬²»¿Éɾ³ýÕûÕÅ±í¡£
2.ÔÚʹÓÃinɾ³ýÒªÁìʱ£¬Òª×¢ÖØת´ïµÄ²ÎÊýÊÇÒ»¸öÊý×飬²¢ÇÒ¸ÃÊý×é±ØÐè°üÀ¨¶à¸öÖµ¡£
3.ÔÚʹÓÃinɾ³ýÒªÁìʱ£¬ÎñÐëҪעÖزÎÊýµÄÇå¾²ÐÔ£¬×èÖ¹SQL×¢ÈëµÈΣº¦¡£
ÒÔÉϾÍÊÇthinkphpÖÐinɾ³ýÒªÁìµÄʹÓúÍÓ¦Óó¡¾°ÊÇʲôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡