尊龙凯时人生就是搏

thinkphp5ŲÓô洢Àú³Ì

ÔÚ¿ª·¢webÓ¦ÓóÌÐòʱ£¬¾­³£ÐèҪŲÓô洢Àú³ÌÀ´Ö´ÐÐһЩÖØ´óµÄÊý¾Ý¿â²Ù×÷¡£thinkphp5×÷Ϊһ¿î¹ãÊܽӴýµÄphp¿ò¼Ü£¬ÔÚÊý¾Ý¿â²Ù×÷·½ÃæÌṩÁËÀû±ã¿ì½ÝµÄ½â¾ö¼Æ»®¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphp5ÖÐŲÓô洢Àú³Ì¡£

½¨Éè´æ´¢Àú³Ì

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚÊý¾Ý¿âÖн¨ÉèÒ»¸ö´æ´¢Àú³Ì¡£ÕâÀïÒÔMySQLΪÀý£¬¼ÙÉèÎÒÃÇÒѾ­½¨ÉèÁËÈçϵĴ洢Àú³Ì£º

DELIMITER $$
CREATE PROCEDURE user_login(IN `username` varchar(50), IN `password` varchar(50), OUT `result` varchar(20))
BEGIN
    SELECT COUNT(*) INTO result FROM user WHERE `username`=username AND `password`=password;
END $$
DELIMITER ;

µÇ¼ºó¸´ÖÆ

¸Ã´æ´¢Àú³ÌÓÃÓÚÑéÖ¤Óû§µÇ¼ÐÅÏ¢£¬½ÓÊÜÁ½¸öÊäÈë²ÎÊý£ºÓû§ÃûºÍÃÜÂ룬ÒÔ¼°Ò»¸öÊä³ö²ÎÊý£ºµÇ¼Ч¹û¡£

ÔÚÄ£×ÓÖÐŲÓÃ

½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÔÚÏìÓ¦µÄÄ£×ÓÖÐŲÓô洢Àú³Ì¡£¹ØÓÚÒÑÓеÄÄ£×Ó£¬¿ÉÒÔÔÚÏìÓ¦µÄÒªÁìÖÐÌí¼ÓÈçÏ´úÂ룺

$result = Db::query("CALL user_login('".$username."','".$password."',@result);");

µÇ¼ºó¸´ÖÆ

ÕâÀïʹÓÃÁËDb::queryÒªÁìÀ´Ö´Ðд洢Àú³Ì¡£µÚÒ»¸ö²ÎÊýÊÇ´æ´¢Àú³ÌµÄSQLÓï¾ä£¬×¢ÖØʹÓÃË«ÒýºÅ°ü¹ü²ÎÊýÖµ¡£µÚ¶þ¸ö²ÎÊýÊÇÒ»¸öÒýÓñäÁ¿£¬ÓÃÓÚ»ñÈ¡´æ´¢Àú³ÌµÄÊä³öЧ¹û¡£ÔÚ´Ë֮ǰ£¬ÐèÒªÏȽç˵һ¸ö±äÁ¿À´ÉúÑÄÊä³öЧ¹û£º

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

$result = '';

µÇ¼ºó¸´ÖÆ

×îºó£¬ÎÒÃÇÐèÒªÔÚÖ´Ðд洢Àú³Ì֮ǰÌí¼ÓÈçÏ´úÂ룬ÒÔ°ü¹ÜÊä³ö²ÎÊýÄܹ»×¼È·»ñÈ¡£º

Db::query("SELECT @result AS result;");

µÇ¼ºó¸´ÖÆ

ÍêÕû´úÂëÈçÏ£º

public function login($username, $password)
{
    $result = '';

    Db::query("SELECT @result := '';");

    $result = Db::query("CALL user_login('".$username."','".$password."',@result);");

    Db::query("SELECT @result AS result;");

    return intval($result[0]['result']) === 1;
}

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬intvalº¯ÊýÓÃÓÚ½«×Ö·û´®×ª»»³ÉÕûÐÍ¡£

¹ØÓÚÐÂÔöµÄÄ£×Ó£¬¿ÉÒÔƾ֤ÈçÏ°취¾ÙÐвÙ×÷£º

н¨Ò»¸öÄ£×ÓÀ࣬ÀýÈçUserModel£¬²¢Ìí¼ÓÈçÏ´úÂ룺

  
  
   µÇ¼ºó¸´ÖÆ
  

ÔÚ¿ØÖÆÆ÷ÖÐŲÓÃÄ£×ÓÒªÁ죬ÀýÈ磺

public function login()
{
    $username = input('post.username');
    $password = input('post.password');

    if(UserModel::login($username, $password)){
        return json(['code' => 0, 'message' => 'µÇ¼ÀÖ³É']);
    } else {
        return json(['code' => -1, 'message' => 'µÇ¼ʧ°Ü']);
    }
}

µÇ¼ºó¸´ÖÆ

ÔËÐгÌÐò£¬ÈôÊÇÒ»ÇÐÕý³££¬Ó¦¸ÃÄܹ»ÀֳɵǼ¡£

×ܽá

ͨ¹ý±¾ÎĵÄÏÈÈÝ£¬ÎÒÃÇѧϰÁËÔõÑùÔÚThinkPHP5ÖÐŲÓô洢Àú³Ì¡£ÐèҪעÖصÄÊÇ£¬ÔÚÖ´Ðд洢Àú³Ì֮ǰ£¬±ØÐèÏÈÉèÖÃÊä³ö²ÎÊý£¬²¢ÔÚÖ´ÐÐÖ®ºóÅÌÎÊЧ¹û¡£Í¬Ê±£¬ÔÚʹÓÃDb::queryÒªÁìʱ£¬ÐèҪעÖØת´ï²ÎÊýµÄ·½·¨£¬ÒÔ¼°Êä³ö²ÎÊýµÄ»ñÈ¡·½·¨¡£Í¨¹ýºÏÀíʹÓô洢Àú³Ì£¬ÎÒÃÇ¿ÉÒÔÔÚ¿ª·¢Àú³ÌÖиüÀû±ãµØÖ´ÐÐÖØ´óµÄÊý¾Ý¿â²Ù×÷¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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