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

thinkphpÔõÑùʹÓÃORM¾ÙÐÐÊý¾Ý¿â²Ù×÷

ThinkPHP ÊÇÒ»¿î»ùÓÚ PHP µÄ Web ¿ª·¢¿ò¼Ü £¬Ëü¾ßÓпìËÙ¡¢ÇáÓ¯¡¢Çå¾²µÄÌص㠣¬²¢ÇÒ±»ÆÕ±éµØʹÓ᣸ÃϵͳµÄORMÓ³Éä²ãÊÇ×îÒªº¦µÄ £¬ËüÄܹ»ÇáËÉ´¦ÀíÊý¾Ý¿â²Ù×÷¶øÎÞÐè±àдSQLÓï¾ä¡£¿ÉÊÇÓÐʱ¼äÔÚ¿ª·¢Àú³ÌÖл᷺ÆðÐèÒªÅŲé SQL Óï¾äµÄÇéÐÎ £¬Õâʱ¼äÎÒÃǾÍÐèÒªÈà ThinkPHP Ö´ÐÐ SQL¡£

ÔÚ ThinkPHP ÖÐ £¬Ê¹Óà ORM ¾ÙÐÐÊý¾Ý¿â²Ù×÷ÓÐÁ½ÖÖÇéÐÎ £¬Ò»ÖÖÊÇͨ¹ýÄ£×ÓÀ´²Ù×÷ £¬ÁíÒ»ÖÖÊÇͨ¹ý Query ÀàÀ´²Ù×÷¡£

1¡¢Ä£×Ó²Ù×÷

Ä£×Ó²Ù×÷ÊÇʹÓà ORM À´¾ÙÐÐÊý¾Ý¿â²Ù×÷µÄÒ»ÖÖ·½·¨ £¬Í¨¹ýÄ£×Ó²Ù×÷¿ÉÒÔºÜÀû±ãµØ¾ÙÐÐÔöɾ¸Ä²é²Ù×÷ £¬²¢ÇÒ²»ÐèÒª±àд SQL Óï¾ä¡£ÓÐʱÐèҪʹÓô¿´âµÄ SQL ÅÌÎÊ £¬ÀýÈç²éÕÒij¸öÁеÄ×î´óÖµ¡¢×îСֵµÈ¡£

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

ÔÚÄ£×ÓÅÌÎʵĻù´¡ÉÏ £¬ThinkPHP ÌṩÁËÒ»¸ö Db Àà £¬Í¨¹ýËü¿ÉÒÔÖ´ÐÐÔ­Éú SQL £¬ÈçÏÂËùʾ£º

use think\facade\Db;

// Ö´ÐÐÔ­Éú SQL
Db::query('SELECT * FROM `user` WHERE `id` = 1');

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬ÎÒÃÇͨ¹ý Db::query() ÒªÁìÀ´Ö´ÐÐÔ­Éú SQL Óï¾ä¡£Õâ¸öÒªÌå»á·µ»ØÒ»¸öÊý×é £¬°üÀ¨ÅÌÎÊЧ¹û¡£

2¡¢Query Àà²Ù×÷

Query ÀàÊÇ ThinkPHP ÖÐÌṩµÄÒ»¸öÁ´Ê½²Ù×÷Àà £¬Ëü¿ÉÒÔÀû±ãµØ¹¹½¨ SQL Óï¾ä £¬²¢ÇÒÖ§³ÖÔ­Éú SQL ÅÌÎÊ¡£

ʹÓà Query Àà²Ù×÷ SQL µÄ»ù±¾Ó÷¨ÈçÏ£º

use think\facade\Db;

$query = Db::table('user');

$data = $query->where('id', 1)
    ->field('id, name')
    ->select();

// Ö´ÐÐÔ­Éú SQL
$sql = $query->fetchSql(true)->find();

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖÐ £¬ÎÒÃÇÊ×ÏÈͨ¹ý Db::table() ÒªÁìÀ´»ñÈ¡Ò»¸ö Query À๤¾ß £¬È»ºóÔÚ Query À๤¾ßÉϾÙÐÐÁ´Ê½²Ù×÷ £¬Ê¹Óà where() ÒªÁìÌí¼ÓÅÌÎÊÌõ¼þ £¬Ê¹Óà field() ÒªÁìÑ¡ÕªÒªÅÌÎʵÄ×ֶΠ£¬Ê¹Óà select() ÒªÁìÅÌÎÊЧ¹û¡£

ÈôÊÇÐèÒªÖ´ÐÐÔ­Éú SQL Óï¾ä £¬Ö»ÐèÒªÔÚ Query À๤¾ßŲÓà fetchSql(true) ÒªÁì¼´¿É £¬¸ÃÒªÁ콫·µ»ØÌìÉúµÄ SQL Óï¾ä¡£

ÒÔÉϾÍÊÇthinkphpÔõÑùʹÓÃORM¾ÙÐÐÊý¾Ý¿â²Ù×÷µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ