尊龙凯时人生就是博

laravelŲÓô洢Àú³Ì

ÔÚlaravel¿ª·¢ÖУ¬´æ´¢Àú³ÌÊÇÊý¾Ý¿âµÄÒ»¸öÖ÷Òª×é³É²¿·Ö£¬Ëü¿ÉÒÔ×ÊÖúÎÒÃǸüºÃµØÖÎÀíÊý¾Ý¿â£¬Ìá¸ßÅÌÎÊЧÂÊ£¬ïÔÌ­´úÂëÂß¼­ºÍÊý¾Ý¿âÅþÁ¬Á¿µÈ·½ÃæµÄÎÊÌâ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlaravelÓ¦ÓóÌÐòÖÐŲÓô洢Àú³Ì¡£

Ò»¡¢Ê²Ã´ÊÇ´æ´¢Àú³Ì

´æ´¢Àú³ÌÊÇÒ»×éÔ¤±àÒëµÄSQLÓï¾ä£¬Ëü±»ÉúÑÄÔÚÊý¾Ý¿âÖУ¬²¢×÷Ϊ¿ÉÖظ´Ê¹ÓõÄÀú³Ì»òº¯ÊýŲÓá£ÓëSQLÓï¾ä²î±ð£¬´æ´¢Àú³Ì°üÀ¨¿ØÖÆÂß¼­ºÍSQLÓï¾ä£¬¿ÉÒÔ½ÓÊܲÎÊý¡¢·µ»Ø¶à¸öÖµ£¬Ò²¿ÉÒÔʹÓÃÔÝʱ±íµÈ¡£´æ´¢Àú³Ì¿ÉÒÔÌá¸ßÓ¦ÓóÌÐòµÄÐÔÄܺÍÇå¾²ÐÔ£¬¼ò»¯Ó¦ÓóÌÐòµÄÖØ´óÐÔ£¬²¢ïÔÌ­Êý¾Ý¿âºÍÓ¦ÓóÌÐòÖ®¼äµÄÍù·µÍ¨Ñ¶¡£

¶þ¡¢½¨Éè´æ´¢Àú³Ì

ÔÚMySQLÖУ¬½¨Éè´æ´¢Àú³ÌÐèҪʹÓÃCREATE PROCEDUREÓï¾ä£¬Óï·¨ÈçÏ£º

CREATE PROCEDURE procedure_name ([IN | OUT | INOUT] parameter_name data_type [(length)],...)
[SQLÓï¾ä]

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬procedure_nameÊÇ´æ´¢Àú³ÌÃû³Æ£¬parameter_nameÌåÏÖ²ÎÊýÃû³Æ£¬data_typeÌåÏÖ²ÎÊýÊý¾ÝÀàÐÍ£¬lengthÌåÏÖÊý¾Ý³¤¶È¡£²ÎÊý¿ÉÒÔÊÇINÌåÏÖÊäÈë²ÎÊý£¨Ö»ÄܽøÈë´æ´¢Àú³ÌʹÓã©£¬OUTÌåÏÖÊä³ö²ÎÊý£¨Ö»ÄÜͨ¹ý´æ´¢Àú³Ì»ñÈ¡Êý¾Ý£©£¬INOUTÌåÏּȿÉÒÔÊäÈëÓÖ¿ÉÒÔÊä³ö¡£

ÀýÈ磬ÎÒÃǽ¨ÉèÒ»¸ö»ñÈ¡Óû§ÐÅÏ¢µÄ´æ´¢Àú³ÌgetUserInfo£¬´úÂëÈçÏ£º

CREATE PROCEDURE getUserInfo(IN userId INT)
BEGIN
    SELECT * FROM users WHERE id = userId;
END

µÇ¼ºó¸´ÖÆ

ͨ¹ý¸Ã´æ´¢Àú³Ì£¬ÎÒÃÇ¿ÉÒÔ»ñÈ¡µ½Ö¸¶¨idµÄÓû§ÐÅÏ¢¡£

Èý¡¢Å²Óô洢Àú³Ì

ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃDBÃÅÃæÌṩҪÁìDB::selectÀ´Ö´Ðд洢Àú³Ì£¬ÀýÈ磺

$result = DB::select("CALL getUserInfo(1)");

µÇ¼ºó¸´ÖÆ

ÕâÀïÎÒÃÇÒÔ»ñÈ¡idΪ1µÄÓû§ÐÅϢΪÀý£¬Í¨¹ýCALLÓï¾äÀ´Å²ÓÃÒѽ¨ÉèµÄgetUserInfo´æ´¢Àú³Ì¡£Å²ÓÃÀֳɺó£¬$result»á·µ»ØÒ»¸ö°üÀ¨Óû§ÐÅÏ¢µÄ¹¤¾ß¡£

ÈôÊÇÐèҪת´ï²ÎÊý£¬¿ÉÒÔʹÓÃռλ·û£¬ÀýÈ磺

$result = DB::select("CALL getUserInfo(?)", [1]);

µÇ¼ºó¸´ÖÆ

ÕâÀïµÄռλ·ûÊÇÎʺţ¬µÚ¶þ¸ö²ÎÊýÊÇÊý×éÐÎʽ£¬ÐèÒª¶ÔÓ¦¸øÎʺŸ³Öµ¡£

ÖµµÃ×¢ÖصÄÊÇ£¬ÓÐЩ´æ´¢Àú³ÌÐèÒª·µ»ØЧ¹û¼¯£¬¶øÓÐЩֻÐèÒªÖ´Ðиüлò²åÈë²Ù×÷£¬Í¨¹ýDBÃÅÃæÌṩҪÁìDB::statement¿ÉÖ±½ÓŲÓã¬ÀýÈ磺

DB::statement("CALL updateUser(1, 'John')");

µÇ¼ºó¸´ÖÆ

ÕâÀïÎÒÃÇŲÓõÄÊÇupdateUser´æ´¢Àú³Ì£¬¸üÐÂidΪ1µÄÓû§ÐÅÏ¢£¬²»±£´æ·µ»ØЧ¹û¼¯ÇéÐΡ£

ËÄ¡¢Ê¹ÓÃORMŲÓô洢Àú³Ì

³ýÁËͨ¹ýDBÃÅÃæŲÓô洢Àú³Ì£¬LaravelµÄORMÒ²ÌṩÁËŲÓô洢Àú³ÌµÄÒªÁ죬Óï·¨ÈçÏ£º

$results = User::hydrate(
    DB::select("CALL getUserInfo(?)", array($id))
);

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬User´ú±íÓû§±í¡£´ËÒªÁìÓëDB::selectÒªÁìÀàËÆ£¬Í¨¹ýת´ï²ÎÊýÀ´Å²ÓÃgetUserInfo´æ´¢Àú³Ì£¬²¢Í¨¹ýhydrateÒªÁ콫Ч¹û´æÈëÄ£×ÓÖС£

×ܽá

LaravelÌṩÁËÀû±ãµÄÒªÁìÀ´Å²Óô洢Àú³Ì¡£Í¨¹ýDBÃÅÃæºÍORM£¬¿ÉÒÔÖ±½Óͨ¹ýCALLÓï¾äŲÓÃÒѽ¨ÉèµÄ´æ´¢Àú³Ì£¬²¢»ñÈ¡·µ»ØЧ¹û¼¯»ò¸üÐÂÊý¾Ý¡£´æ´¢Àú³Ì¿ÉÒÔ×ÊÖúÎÒÃǸüºÃµØÖÎÀíÊý¾Ý¿â£¬Ìá¸ßÓ¦ÓóÌÐòµÄÐÔÄܺÍÇå¾²ÐÔ£¬Ò²¿ÉÒÔ¼ò»¯Ó¦ÓóÌÐòµÄÖØ´óÐÔ¡£

ÒÔÉϾÍÊÇlaravelŲÓô洢Àú³ÌµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ