Ò»ÎÄÏê½âthinkphp concatÓ÷¨
ʹÓÃthinkphpµÄ¿ª·¢ÕßÃǶ¼ÖªµÀ£¬thinkphpÖеÄconcat()º¯Êý¿ÉÒÔ½«¶à¸ö×Ö·û´®Æ´½Ó³ÉÒ»¸ö×Ö·û´®¡£Õâ¸öº¯ÊýÊǺÜÊÇÓÐÓõģ¬ÌØÊâÊÇÔÚÅÌÎÊÊý¾Ý¿âʱ¡£±¾ÎĽ«ÏÈÈÝconcat()º¯ÊýµÄÓ÷¨¼°ÆäʾÀý¡£
concat()º¯ÊýµÄÓï·¨ºÍÓ÷¨
Ò»Ñùƽ³£ÇéÐÎÏ£¬¸Ãº¯ÊýµÄÓï·¨ÈçÏÂËùʾ£º
concat(string1,string2,…)
¸Ãº¯ÊýµÄ²ÎÊý¿ÉÒÔÊÇÁ½¸ö»ò¶à¸ö×Ö·û´®¡£²ÎÊýÖ®¼äÓöººÅÍÑÀë¡£concat()º¯Êý»á½«ÕâЩ²ÎÊýÅþÁ¬³ÉÒ»¸öµ¥¶ÀµÄ×Ö·û´®£¬²¢½«Ð§¹û·µ»Ø¡£ÒÔÏÂÊÇÒ»¸öʾÀý£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
$User = M(‘User’);
$User->where(“concat(firstname,’ ‘,lastname)=’John Smith'”)->find();
ÕâÊÇÒ»¸öÅÌÎÊ£¬Ëü½«ÔÚÊý¾Ý¿âÖвéÕÒÃûΪJohn SmithµÄÓû§¡£Õâ¸öÅÌÎÊʹÓÃÁËconcat()º¯Êý£¬½«Êý¾Ý¿âÖеÄfirstnameºÍlastname×Ö¶ÎÅþÁ¬ÆðÀ´¡£
concat()º¯Êý»¹¿ÉÒÔÓÃÀ´¸üÐÂÊý¾Ý¿âÖеļͼ¡£ÒÔÏÂÊÇÒ»¸öʾÀý£º
$User = M(‘User’);
$User->where(‘id=1’)->save(array(‘username’=>concat(‘firstname’,’lastname’)));
Õâ¸öʾÀýÑÝʾÁËÔõÑùÔÚ½«Á½¸ö×ֶκϲ¢³ÉÒ»¸ö×ֶβ¢½«ÆäÉúÑĵ½Êý¾Ý¿âÖС£
concat_ws()º¯ÊýµÄÓï·¨ºÍÓ÷¨
³ýÁËconcat()º¯Êý£¬ThinkPHP»¹ÌṩÁËÒ»¸öÃûΪconcat_ws()µÄº¯Êý¡£concat_ws()º¯Êý½«Ò»¸öÍÑÀë·û²åÈëµ½ÅþÁ¬µÄ×Ö·û´®Ö®¼ä¡£ÆäÓï·¨ÈçÏÂËùʾ£º
concat_ws(separator,string1,string2,…)
¸Ãº¯ÊýµÄµÚÒ»¸ö²ÎÊýÊÇÍÑÀë·û¡£²ÎÊýÖ®¼äÓöººÅÍÑÀë¡£ÒÔÏÂÊÇÒ»¸öʾÀý£º
$User = M(‘User’);
$User->where(“concat_ws(‘ ‘,firstname,lastname)=’John Smith'”)->find();
Õâ¸öʾÀýÓëÉÏÃæµÄʾÀýºÜÊÇÏàËÆ£¬¿ÉÊÇËüʹÓÃÁËconcat_ws()º¯Êý£¬½«¿Õ¸ñ×÷ΪÍÑÀë·ûÀ´ÅþÁ¬firstnameºÍlastname¡£
ʵÀýÑÝʾ
²»ÄÑ·¢Ã÷£¬Ê¹ÓÃconcat()º¯ÊýºÍconcat_ws()º¯ÊýÓï¾äºÜÊÇÏàËÆ£¬ºÏÀíÑ¡Ôñ»áÈôúÂëÏÔµÃÔ½·¢¾«Á·¡¢Ò×ÓÚά»¤¡£
ʾÀý
¼ÙÉèÓÐÒ»¸öÓû§±í¸ñ£¬ÆäÖаüÀ¨id¡¢firstnameºÍlastname×ֶΣ¬ÐèҪʹÓÃconcat()º¯Êý½«firstnameºÍlastnameÆ´½Ó³ÉÓû§Ãû²¢¾ÙÐÐÅÌÎÊ¡£¼ÙÉèÒª²éÕÒÓû§ÃûΪ¡°John Smith¡±µÄÓû§£¬´úÂëÈçÏÂËùʾ£º
$User = M(‘User’);
$User->where(“concat(firstname,’ ‘,lastname)=’John Smith'”)->find();
¶øʹÓÃconcat_ws()º¯Êý£¬Í¬ÑùµÄ²Ù×÷¿ÉÒÔÔ½·¢ÇåÎú£º
$User = M(‘User’);
$User->where(“concat_ws(‘ ‘,firstname,lastname)=’John Smith'”)->find();
ÔÚÏÖʵʹÓÃÖУ¬concat()º¯ÊýºÍconcat_ws()º¯ÊýµÄÓ¦ÓúÜÊÇÆձ飬ÌØÊâÊÇÔÚÅÌÎʺ͸üÐÂÊý¾Ý¿âʱ¡£¿ª·¢ÕßÃÇ¿ÉÒÔ³ä·ÖʹÓÃËüÃǵĹ¦Ð§£¬ÈÃ×Ô¼ºµÄ´úÂëÔ½·¢ÕûÆë¡¢¼òÆÓºÍÒ×ÓÚά»¤¡£
ÒÔÉϾÍÊÇÒ»ÎÄÏê½âthinkphp concatÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡