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

thinkphpÔõô»ñȡij×Ö¶Î

thinkphpÊÇÒ»ÖÖÊ¢ÐеÄphp¿ªÔ´¿ò¼Ü£¬ÓÃÓÚ¿ìËÙ¿ª·¢webÓ¦ÓóÌÐò¡£ÔÚ¿ª·¢Àú³ÌÖУ¬¾­³£ÐèÒª´ÓÊý¾Ý¿âÖлñȡij¸ö×ֶεÄÖµ¡£±¾ÎĽ«ÏÈÈÝÔÚthinkphpÖÐÔõÑù»ñȡij¸ö×ֶεÄÖµ¡£

Ò»¡¢Ê¹ÓÃÄ£×ÓÒªÁì»ñÈ¡×Ö¶Î

1.µ¥ÌõÊý¾ÝÅÌÎÊ

ÔÚthinkphpÖУ¬Ê¹ÓÃÄ£×ÓÒªÁì»ñÈ¡×Ö¶ÎÊÇ×î³£¼ûµÄÒªÁìÖ®Ò»¡£ÔÚµ¥ÌõÊý¾ÝÅÌÎʳ¡¾°ÖУ¬¿ÉÒÔʹÓÃfindÒªÁì»ñÈ¡Ö¸¶¨×ֶεÄÖµ¡£ÀýÈ磬ÎÒÃÇÓÐÒ»¸öUserÄ£×Ó£¬ÏëÒª»ñÈ¡idΪ1µÄÓû§µÄÓû§Ãû£¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

$user = User::find(1);
$username = $user->username;

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇʹÓÃUser::find(1)ÒªÁì»ñÈ¡idΪ1µÄÓû§µÄÐÅÏ¢£¬²¢½«Ð§¹û¸³¸ø±äÁ¿$user¡£È»ºóÎÒÃÇ¿ÉÒÔʹÓÃ$user->username»ñÈ¡Óû§Ãû¡£

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

2.¶àÌõÊý¾ÝÅÌÎÊ

ÈôÊÇÄãÐèÒª´Ó¶àÌõÊý¾ÝÖлñÈ¡Ö¸¶¨×ֶεÄÖµ£¬¿ÉÒÔʹÓÃselectÒªÁì¡£ÀýÈ磬ÎÒÃÇÒª»ñÈ¡ËùÓÐÓû§µÄ¶¼»á£¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

$users = User::select();
foreach($users as $user){
    $city = $user->city;
    // do something
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇʹÓÃUser::select()ÒªÁì»ñÈ¡ËùÓÐÓû§ÐÅÏ¢£¬²¢½«Ð§¹ûÉúÑÄÔÚ$users±äÁ¿ÖС£È»ºóÎÒÃÇʹÓÃforeachÑ­»·±éÀúÿ¸öÓû§£¬ÓÃ$user->city»ñÈ¡¶¼»áÃû³Æ²¢×öһЩ²Ù×÷¡£

¶þ¡¢Ê¹ÓÃÊý¾Ý¿âÅÌÎÊÓï¾ä»ñÈ¡×Ö¶Î

ÁíÒ»ÖÖÒªÁìÊÇʹÓÃÊý¾Ý¿âÅÌÎÊÓï¾ä»ñÈ¡×Ö¶ÎÐÅÏ¢¡£ÔÚthinkphpÖУ¬¿ÉÒÔʹÓÃDbÀà²Ù×÷Êý¾Ý¿â¡£ÒÔÏÂÊÇһЩ³£ÓõÄÒªÁ죺

1.ÅÌÎʵ¥¸ö×Ö¶ÎÖµ

ÈôÊÇÄãÖ»ÐèÒªÅÌÎÊij¸ö×ֶεÄÖµ£¬¿ÉÒÔʹÓÃvalueÒªÁì¡£ÀýÈ磬ÎÒÃÇÒªÅÌÎÊidΪ1µÄÓû§µÄ¶¼»á£¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

$city = Db::name('user')->where('id', 1)->value('city');

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇʹÓÃDb::name(‘user’)ÒªÁì»ñÈ¡user±íµÄ¹¤¾ß£¬²¢Ê¹ÓÃwhereÒªÁìÖ¸¶¨ÅÌÎÊÌõ¼þ¡£×îºó£¬ÎÒÃÇŲÓÃvalueÒªÁì»ñÈ¡city×ֶεÄÖµ¡£

2.ÅÌÎʶà¸ö×Ö¶ÎÖµ

ÈôÊÇÄãÐèҪͬʱÅÌÎʶà¸ö×ֶεÄÖµ£¬¿ÉÒÔʹÓÃfieldÒªÁì¡£ÀýÈ磬ÎÒÃÇÒªÅÌÎÊidΪ1µÄÓû§µÄ¶¼»áºÍÓʱ࣬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

$user = Db::name('user')->field('city, zip')->where('id', 1)->find();
$city = $user['city'];
$zip = $user['zip'];

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇʹÓÃfield(‘city, zip’)ÒªÁìÖ¸¶¨ÅÌÎʵÄ×ֶΣ¬Ê¹ÓÃfindÒªÁìÅÌÎʵ¥ÌõÊý¾Ý£¬²¢½«Ð§¹ûÉúÑÄÔÚ$user±äÁ¿ÖС£×îºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃ$user[‘city’]ºÍ$user[‘zip’]»ñÈ¡¶¼»áºÍÓʱà¡£

3.ÅÌÎʶàÌõÊý¾ÝÖеÄ×Ö¶Î

ÈôÊÇÄãÐèÒª´Ó¶àÌõÊý¾ÝÖлñÈ¡Ìض¨µÄ×ֶΣ¬¿ÉÒÔʹÓÃcolumnÒªÁì¡£ÀýÈ磬ÎÒÃÇÒª»ñÈ¡ËùÓÐÓû§µÄÓÊÏ䣬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

$emails = Db::name('user')->column('email');

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇʹÓÃcolumn(’email’)ÒªÁì»ñÈ¡user±íÖÐËùÓеÄemail×Ö¶ÎÖµ£¬²¢½«Ð§¹ûÉúÑÄÔÚ$emails±äÁ¿ÖС£

Èý¡¢×ܽá

ÒÔÉÏÊÇÔÚthinkphpÖлñȡij¸ö×ֶεÄÒªÁì¡£ÔÚÏÖʵ¿ª·¢ÖУ¬Æ¾Ö¤Ïêϸ³¡¾°Ñ¡ÔñºÏÊʵÄÒªÁì¿ÉÒÔÌá¸ß¿ª·¢Ð§ÂÊ¡£ÎÞÂÛʹÓÃÄ£×ÓÒªÁìÕÕ¾ÉÊý¾Ý¿âÅÌÎÊÓï¾ä£¬¶¼¿ÉÒÔÇáËÉ»ñÈ¡ÏëÒªµÄ×Ö¶ÎÐÅÏ¢¡£

ÒÔÉϾÍÊÇthinkphpÔõô»ñȡij×ֶεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

13452372176

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

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

QR code
ÍøÕ¾µØͼ