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

thinkphpÔõôƾ֤idÅÌÎÊ×ֶεÄÖµ

thinkphpÊÇÒ»¿îºÜÊÇÊ¢ÐеÄphp¿ª·¢¿ò¼Ü£¬ËüÌṩÁËÐí¶àºÃÓõĹ¦Ð§ºÍÒªÁì×ÊÖúÎÒÃÇ¿ìËٵؾÙÐÐwebÓ¦ÓóÌÐòµÄ¿ª·¢¡£ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃǾ­³£ÐèҪƾ֤ij¸öÊý¾Ý±íµÄÖ÷¼üidÀ´ÅÌÎʶÔÓ¦µÄ¼Í¼ÐÅÏ¢»ò×ֶεÄÖµ£¬ÏÂÃæÏÈÈÝʹÓÃthinkphp¿ò¼Ü¾ÙÐÐƾ֤idÅÌÎÊ×Ö¶ÎÖµµÄÒªÁì¡£

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏàʶThinkPHP¿ò¼ÜÖвÙ×÷Êý¾Ý¿âµÄ»ù±¾²Ù×÷£¬°üÀ¨Êý¾Ý¿âÅþÁ¬¡¢Êý¾Ý±í²Ù×÷¡¢ÅÌÎʲÙ×÷µÈ¡£¼ÙÉèÎÒÃÇÏÖÔÚÓÐÒ»¸öÊý¾Ý±í½Ð×öuser£¬ËüµÄÖ÷¼üÊÇid£¬ÆäÖаüÀ¨ÒÔÏÂ×ֶΣºname£¬age£¬gender£¬emailµÈ¡£ÎÒÃÇÏÖÔÚҪƾָ֤¶¨µÄidÈ¥ÅÌÎʶÔÓ¦µÄname×ֶεÄÖµ¡£

µÚÒ»²½£¬ÅþÁ¬Êý¾Ý¿â¡£

ÔÚThinkPHP¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔÔÚconfigĿ¼ÏÂÃæµÄdatabase.phpÎļþÖнç˵ÅþÁ¬Êý¾Ý¿âµÄÉèÖÃÐÅÏ¢¡£ÀýÈ磺

return [
    // Êý¾Ý¿âÀàÐÍ
    'type'        => 'mysql',
    // Êý¾Ý¿âÅþÁ¬DSNÉèÖÃ
    'dsn'         => '',
    // Ð§ÀÍÆ÷µØµã
    'hostname'    => 'localhost',
    // Êý¾Ý¿âÃû
    'database'    => 'test',
    // Êý¾Ý¿âÓû§Ãû
    'username'    => 'root',
    // Êý¾Ý¿âÃÜÂë
    'password'    => 'root',
    // Êý¾Ý¿âÅþÁ¬¶Ë¿Ú
    'hostport'    => '3306',
    // Êý¾Ý¿âÅþÁ¬²ÎÊý
    'params'      => [],
    // Êý¾Ý¿â±àÂëĬÈϽÓÄÉutf8
    'charset'     => 'utf8',
    // Êý¾Ý¿â±íǰ׺
    'prefix'      => 'tp_',
    // ÊÇ·ñÐèÒª¶ÏÏßÖØÁ¬
    'break_reconnect' => true,
];

µÇ¼ºó¸´ÖÆ

ͨ¹ýÉÏÊöÉèÖÃÐÅÏ¢£¬ÎÒÃÇ¿ÉÒÔÅþÁ¬µ½ÃûΪtestµÄMySQLÊý¾Ý¿â¡£

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

µÚ¶þ²½£¬¾ÙÐÐÊý¾Ý¿âÅÌÎʲÙ×÷¡£

ÔÚThinkPHP¿ò¼ÜÖУ¬Ê¹ÓÃDbÀàÀ´²Ù×÷Êý¾Ý¿â¡£ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷´úÂëÖмÓÈëÒÔÏ´úÂ룺

use think\Db;

class UserController extends Controller
{
    // Æ¾Ö¤IDÅÌÎÊÓû§ÐÕÃû
    public function getUserName($id)
    {
        $result = Db::table('user')->where(['id' => $id])->value('name');
        return $result;
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚgetUserNameÒªÁìÖУ¬ÎÒÃÇʹÓÃDbÀàµÄtableÒªÁìÖ¸¶¨ÒªÅÌÎʵÄÊý¾Ý±í£¬Ê¹ÓÃwhereÒªÁìÖ¸¶¨ÅÌÎÊÌõ¼þ£¬ÆäÖÐ[‘id’ => $id]ÌåÏÖÅÌÎÊid¼´ÊÇÖ¸¶¨$idÖµµÄ¼Í¼£¬×îºóʹÓÃvalueÒªÁìÀ´»ñÈ¡name×ֶεÄÖµ¡£ÔÚÏÖʵµÄÓ¦ÓÃÖУ¬getUserNameÒªÁì¿ÉÄܻ᷵»Ø¶à¸ö×ֶεÄÖµ£¬´Ëʱ¿ÉÒÔʹÓÃfindÒªÁìÀ´»ñÈ¡ÅÌÎʵ½µÄÒ»ÕûÌõ¼Í¼£¬ÀýÈ磺

public function getUserInfo($id)
{
    $result = Db::table('user')->where(['id' => $id])->find();
    return $result;
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖУ¬Ê¹ÓÃfindÒªÁì»ñÈ¡ÅÌÎʵ½µÄÒ»ÕûÌõ¼Í¼¡£ÐèҪעÖصÄÊÇ£¬findÒªÁì·µ»ØµÄÊÇÒ»¸ö¹ØÁªÊý×飬ÆäÖмüÃûÊÇÊý¾Ý±íÖеÄ×Ö¶ÎÃû³Æ¡£

×ÛÉÏËùÊö£¬Ê¹ÓÃThinkPHPƾ֤IDÅÌÎÊ×Ö¶ÎÖµ¿ÉÒÔͨ¹ýÒÔÏ°취À´Íê³É£ºÏÈÅþÁ¬µ½Ö¸¶¨µÄÊý¾Ý¿â£¬È»ºóʹÓÃDbÀàÅÌÎÊÊý¾Ý±íÖеļͼ¡£¹ØÓÚÅÌÎʲÙ×÷£¬¿ÉÒÔʹÓÃwhereÒªÁìÖ¸¶¨ÅÌÎÊÌõ¼þ£¬È»ºóŲÓÃvalueÒªÁì»ñÈ¡Ö¸¶¨×ֶεÄÖµ £»ÈôÊÇÒª»ñÈ¡ÕûÌõ¼Í¼£¬¿ÉÒÔʹÓÃfindÒªÁì»ñÈ¡Ò»ÕûÌõ¼Í¼£¬ÆäÖмüÃûÊÇÊý¾Ý±íÖеÄ×Ö¶ÎÃû³Æ¡£

ÒÔÉϾÍÊÇthinkphpÔõôƾ֤idÅÌÎÊ×ֶεÄÖµµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ