thinkphpÔõôÅÌÎÊÊý¾Ý¿âÊä³öÖ¸¶¨×Ö¶ÎÃû
ÔÚʹÓÃphp¾ÙÐÐÍøÕ¾¿ª·¢Ê±£¬ÅÌÎÊÊý¾Ý¿âÊǷǾ³£¼ûµÄ²Ù×÷¡£¶øÔÚʹÓÃthinkphpÕâ¸öÓÅÒìµÄphp¿ª·¢¿ò¼Üʱ£¬ÅÌÎÊÊý¾Ý¿âÒ²ÊǺÜÊÇÀû±ã¿ì½ÝµÄ²Ù×÷¡£±¾ÆªÎÄÕ½«»áÏÈÈÝÔõÑùʹÓÃthinkphpÅÌÎÊÊý¾Ý¿â£¬²¢Êä³öÖ¸¶¨µÄ×ֶΡ£
Ê×ÏÈÐèÒªÅþÁ¬Êý¾Ý¿â
ÔÚThinkPHPÖУ¬ÅþÁ¬Êý¾Ý¿âºÜÊǼòÆÓ¡£ÄúÖ»ÐèÒªÔÚ/config/database.phpÎļþÖÐÉèÖúÃÏìÓ¦µÄÊý¾Ý¿âÐÅÏ¢¼´¿É¡£
ÒÔmysqlÊý¾Ý¿âΪÀý£¬ÉèÖÃÎļþÈçÏ£º
'type' => 'mysql', // Êý¾Ý¿âÀàÐÍ 'hostname' => '127.0.0.1', // ЧÀÍÆ÷µØµã 'database' => 'test_db', // Êý¾Ý¿âÃû 'username' => 'test_user', // Óû§Ãû 'password' => 'test_password', // ÃÜÂë 'hostport' => '3306', // ¶Ë¿ÚºÅ
µÇ¼ºó¸´ÖÆ
¹¹½¨ÅÌÎÊÌõ¼þ
¹¹½¨ÅÌÎÊÌõ¼þÊǾÙÐÐÊý¾Ý¿âÅÌÎʵĵÚÒ»²½¡£Ò»Ñùƽ³£ÇéÐÎÏ£¬ÄúÐèҪʹÓÃThinkPHPÌṩµÄQuery¹¤¾ßÀ´¹¹½¨ÅÌÎÊÌõ¼þ¡£Query¹¤¾ßÊÇÒ»ÖÖÁ´Ê½Å²Óõķ½·¨£¬¿ÉÒÔ¼«´óÀû±ãÄúµÄÅÌÎʲÙ×÷¡£
ÀýÈ磬ÏëÒªÅÌÎÊÓû§±íÖÐage´óÓÚ¼´ÊÇ18ËêµÄÓû§£¬¿ÉÒÔÕâÑù¹¹½¨ÅÌÎÊÌõ¼þ£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
use think\db\Query; $query = new Query(); $query->table('user') ->where('age', '>=', 18); $res = $query->select();
µÇ¼ºó¸´ÖÆ
Êä³öÖ¸¶¨µÄ×Ö¶Î
ÔÚ¾ÙÐÐÅÌÎʲÙ×÷ʱ£¬ÍùÍùÖ»ÐèҪijЩ×ֶεÄÖµ£¬¶ø²»ÐèÒªËùÓÐ×ֶεÄÖµ¡£ÎªÁËÊä³öÖ¸¶¨µÄ×ֶΣ¬Äú¿ÉÒÔÔÚÅÌÎʲÙ×÷ÖмÓÈëfieldÒªÁ죬´«ÈëÒ»¸öÊý×飬Êý×éÄÚ²¿ÊÇÐèÒªÅÌÎʵÄ×Ö¶ÎÃû¡£
ÀýÈ磬ÏÖÔÚÐèÒªÅÌÎÊÓû§±íÖÐËùÓÐ18ËêÒÔÉϵÄÓû§µÄÐÕÃûºÍÄêËê¡£¿ÉÒÔÕâÑù²Ù×÷£º
$query->table('user') ->where('age', '>=', 18) ->field('name, age'); $res = $query->select();
µÇ¼ºó¸´ÖÆ
ÕâÑù£¬ÅÌÎÊЧ¹ûÖн«Ö»°üÀ¨ÐÕÃûºÍÄêËêÁ½¸ö×ֶεÄÖµ£¬ÆäËû×ֶεÄÖµ½«²»»á·ºÆðÔÚÅÌÎÊЧ¹ûÖС£
×ܽá
ÒÔÉϾÍÊÇʹÓÃThinkPHPÅÌÎÊÊý¾Ý¿â£¬²¢Êä³öÖ¸¶¨×ֶεÄÒªÁ졣ͨ¹ýÕâÖÖÒªÁ죬¿ÉÒÔ¿ìËÙÇáËɵؾÙÐÐÊý¾Ý¿âÅÌÎÊ£¬²¢½«ÅÌÎÊЧ¹ûÊä³öΪָ¶¨µÄ×ֶεÄÖµ¡£ÈôÊÇÄúÏëÒªÏàʶ¸ü¶à¹ØÓÚThinkPHPµÄʹÓÃÒªÁ죬¿ÉÒԲο¼¹Ù·½Îĵµ£¬»òÕß¼ÓÈëÏà¹ØÅàѵ¿Î³Ì¡£
ÒÔÉϾÍÊÇthinkphpÔõôÅÌÎÊÊý¾Ý¿âÊä³öÖ¸¶¨×Ö¶ÎÃûµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡