×ðÁú¿­Ê±¹ÙÍøµÇ¼

thinkphp»ñÈ¡²»µ½Êý¾Ý

ÔÚʹÓÃthinkphp±àдÍøվʱ£¬³ £»áÓöµ½»ñÈ¡²»µ½Êý¾ÝµÄÎÊÌâ¡£ÕâÊÇÓÉÓÚthinkphpµÄÊý¾Ý²Ù×÷½ÏÁ¿ÖØ´ó£¬ÐèÒªÕÆÎÕÒ»¶¨µÄ¼¼ÇɲŻª×¼È·²Ù×÷¡£±¾ÎĽ«ÏÈÈݼ¸ÖÖ³£¼ûµÄ»ñÈ¡Êý¾ÝÒªÁìÏ¢Õù¾öÒªÁì¡£

1.ʹÓÃÅÌÎʽṹÆ÷»ñÈ¡Êý¾Ý

ÅÌÎʽṹÆ÷ÊÇthinkphpµÄÒ»ÖÖÊý¾Ý²Ù×÷ÒªÁ죬¿ÉÒÔͨ¹ýÁ´Ê½Å²ÓýṹÆ÷ÒªÁìÀ´»ñÈ¡Êý¾Ý¡£ÀýÈ磺

$data = Db::table('users')->where('id', $id)->find();

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÌåÏÖ»ñÈ¡users±íÖÐIDΪ$idµÄÓû§ÐÅÏ¢¡£¿ÉÊÇ£¬ÈôÊÇÔÚ»ñÈ¡Êý¾ÝʱûÓÐÕÒµ½Æ¥ÅäµÄЧ¹û£¬$data½«»áÊÇÒ»¸ö¿ÕÊý×飬¶ø²»ÊÇnull¡£ÕâÊÇÓÉÓÚfind()ÒªÌå»á·µ»ØÒ»¸öÊý×飬ÈôÊÇÕÒ²»µ½ÈκÎÆ¥ÅäÊý¾Ý£¬Ëü½«·µ»ØÒ»¸ö¿ÕÊý×é¡£

½â¾öÒªÁ죺

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

ÎÒÃÇ¿ÉÒÔʹÓÃempty()º¯ÊýÀ´È·¶¨±äÁ¿ÊÇ·ñΪ¿Õ£¬ÀýÈ磺

$data = Db::table('users')->where('id', $id)->find();
if(empty($data)){
    //ÕÒ²»µ½Æ¥ÅäµÄÊý¾Ý
}else{
    //»ñÈ¡µ½ÁËÆ¥ÅäµÄÊý¾Ý
}

µÇ¼ºó¸´ÖÆ

2.ʹÓÃÄ£×ÓÀà»ñÈ¡Êý¾Ý

ʹÓÃÄ£×ÓÀà»ñÈ¡Êý¾ÝÊÇÒ»¸öÔ½·¢¸ßЧµÄÒªÁì¡£Ê×ÏÈÐèÒª½ç˵һ¸öÄ£×ÓÀ࣬ÀýÈ磺

namespace appmodel;
use thinkModel;

class Users extends Model{
    protected $table = 'users';
    protected $pk = 'id';
}

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÌåÏÖ½ç˵ÁËÒ»¸öÃûΪUsersµÄÄ£×ÓÀ࣬Ëü¼ÌÐø×ÔThinkPHPµÄModelÀ࣬´ú±íÊý¾Ý¿âÖеÄusers±í£¬²¢ÇÒÖ¸¶¨ÁËÖ÷¼üΪID¡£

È»ºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃÄ£×ÓÀàÀ´»ñÈ¡Êý¾Ý£º

$user = Users::get($id);

µÇ¼ºó¸´ÖÆ

Õâ¾ä»°µÄÒâ˼ÊÇ»ñÈ¡IDΪ$idµÄÓû§ÐÅÏ¢¡£ÈôÊÇÕÒµ½ÁËÆ¥ÅäµÄÊý¾Ý£¬$user½«»áÊÇÒ»¸öUsers¹¤¾ß£¬²»È»½«»áÊÇnull¡£

½â¾öÒªÁ죺

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

ÅжÏÄ£×Ó¹¤¾ßÊÇ·ñΪ¿Õ£¬¿ÉÒÔʹÓÃis_null()º¯Êý»òÕßempty()º¯Êý£¬ÀýÈ磺

$user = Users::get($id);
if(is_null($user)){
    //ÕÒ²»µ½Æ¥ÅäµÄÊý¾Ý
}else{
    //»ñÈ¡µ½ÁËÆ¥ÅäµÄÊý¾Ý
}

µÇ¼ºó¸´ÖÆ

3.ʹÓÃÁбíÒªÁì»ñÈ¡Êý¾Ý

¸ü¶àʱ¼ä£¬ÎÒÃÇÐèÒª»ñÈ¡Ò»×éÊý¾Ý¡£Õâ¸öʱ¼ä¿ÉÒÔʹÓÃÁбíÒªÁìÀ´»ñÈ¡Êý¾Ý¡£ÀýÈ磺

$data = Db::table('users')->where('age', '>', 18)->order('id', 'desc')->limit(10)->select();

µÇ¼ºó¸´ÖÆ

Õâ¾ä»°µÄÒâ˼ÊÇ»ñÈ¡ÄêËê´óÓÚ18ËêµÄÇ°10¸öÓû§£¬°´IDµ¹ÐòÅÅÁС£ÈôÊDz»±£´æÇкÏÌõ¼þµÄÊý¾Ý£¬$data½«»áÊÇÒ»¸ö¿ÕÊý×é¡£

½â¾öÒªÁ죺

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

ºÍµÚÒ»ÖÖÒªÁìÀàËÆ£¬ÎÒÃÇÐèҪʹÓÃempty()º¯ÊýÀ´ÅжϱäÁ¿ÊÇ·ñΪ¿Õ¡£

$data = Db::table('users')->where('age', '>', 18)->order('id', 'desc')->limit(10)->select();
if(empty($data)){
    //ÕÒ²»µ½Æ¥ÅäµÄÊý¾Ý
}else{
    //»ñÈ¡µ½ÁËÆ¥ÅäµÄÊý¾Ý
}

µÇ¼ºó¸´ÖÆ

×ܽ᣺

ÒÔÉÏÊÇһЩthinkphp»ñÈ¡²»µ½Êý¾ÝµÄ³£¿´·¨¾öÒªÁ죬ϣÍûÄܹ»¶Ô¸÷ÈËÓÐËù×ÊÖú¡£ËäÈ»£¬Õ⻹ֻÊDZùɽһ½Ç£¬ÎÒÃÇÔÚʹÓÃthinkphpÀú³ÌÖл¹»áÓöµ½¸ü¶àÖØ´óµÄÊý¾Ý²Ù×÷ÇéÐΡ£Ñ§Ï°thinkphpÐèÒªÒ»Ö±ÏàʶºÍʵ¼ù£¬Ìá¸ß×Ô¼ºµÄ±à³Ìˮƽ¡£

ÒÔÉϾÍÊÇthinkphp»ñÈ¡²»µ½Êý¾ÝµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ