尊龙凯时人生就是搏

thinkphpÅÌÎÊÖ¸¶¨×Ö¶ÎÖµµÄÒªÁìÊÇʲô

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

ÔÚʹÓÃThinkPHP¾ÙÐÐÊý¾Ý¿âÅÌÎÊ֮ǰ £¬±ØÐèÏÈÔÚÉèÖÃÎļþÖÐÉèÖÃÊý¾Ý¿âÅþÁ¬ÐÅÏ¢¡£ÔÚconfĿ¼ÏÂÕÒµ½database.phpÉèÖÃÎļþ £¬²¢ÉèÖúÃÊý¾Ý¿âÅþÁ¬ÐÅÏ¢

return [
    // Êý¾Ý¿âÀàÐÍ
    'type'     => 'mysql',
    // ЧÀÍÆ÷µØµã
    'hostname' => 'localhost',
    // Êý¾Ý¿âÃû
    'database' => 'test',
    // ̞
    'username' => 'root',
    // ÃÜÂë
    'password' => '',
    // ¶Ë¿Ú
    'hostport' => '3306',
    // Êý¾Ý¿â±àÂëĬÈϽÓÄÉutf8
    'charset'  => 'utf8',
];

µÇ¼ºó¸´ÖÆ

µÚ¶þ²½£ºÅÌÎÊÖ¸¶¨×ֶεÄÖµ

ʹÓÃThinkPHPÅÌÎÊÖ¸¶¨×ֶεÄÖµºÜÊǼòÆÓ¡£ÎÒÃÇ¿ÉÒÔʹÓÃselectÒªÁìÅÌÎÊÖ¸¶¨×ֶεÄÖµ¡£¾Ù¸öÀý×Ó £¬ÎÒÃÇÓµÓÐÒ»¸öÓû§±í £¬ÄÚÀï°üÀ¨id¡¢Óû§ÃûºÍÃÜÂë¡£ÒªÅÌÎÊËùÓÐÓû§µÄÓû§Ãû £¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

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

// ½¨ÉèÒ»¸öUserÄ£×ÓʵÀý
$user = new \app\model\User();
// ÅÌÎÊËùÓÐÓû§µÄÓû§Ãû
$usernames = $user->field('username')->select();
// ´òÓ¡Óû§Ãû
foreach ($usernames as $username) {
    echo $username['username'] . "<br/>";
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖÐ £¬ÎÒÃÇÊ×ÏȽ¨ÉèÁËÒ»¸öUserÄ£×ÓʵÀý¡£È»ºó £¬ÎÒÃÇʹÓÃfieldÒªÁìÖ¸¶¨ÎÒÃÇÒªÅÌÎʵÄ×Ö¶ÎÃû¡£×îºó £¬ÎÒÃÇʹÓÃselectÒªÁìÅÌÎÊÖ¸¶¨×ֶεÄÖµ¡£ÔÚforeachÑ­»·ÖÐ £¬ÎÒÃÇ´òÓ¡ÁËÿ¸öÓû§Ãû¡£

µÚÈý²½£ºÅÌÎʵ¥¸ö¼Í¼ÖÐÖ¸¶¨×ֶεÄÖµ

ÓÐʱ¼ä £¬ÎÒÃÇÖ»ÐèÒªÅÌÎʵ¥¸ö¼Í¼ÖÐÖ¸¶¨×ֶεÄÖµ¡£ÎÒÃÇ¿ÉÒÔʹÓÃfindÒªÁìÀ´ÊµÏÖÕâ¸ö²Ù×÷¡£ÀýÈç £¬ÎÒÃÇÒªÅÌÎÊidΪ1µÄÓû§µÄÓû§Ãû £¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

// ½¨ÉèÒ»¸öUserÄ£×ÓʵÀý
$user = new \app\model\User();
// ÅÌÎÊidΪ1µÄÓû§µÄÓû§Ãû
$username = $user->where('id', 1)->value('username');
// ´òÓ¡Óû§Ãû
echo $username;

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖÐ £¬ÎÒÃÇÊ×ÏȽ¨ÉèÁËÒ»¸öUserÄ£×ÓʵÀý¡£È»ºó £¬ÎÒÃÇʹÓÃwhereÒªÁìÖ¸¶¨id¼´ÊÇ1µÄ¼Í¼¡£×îºó £¬ÎÒÃÇʹÓÃvalueÒªÁì»ñÈ¡Óû§Ãû×ֶεÄÖµ¡£

µÚËIJ½£ºÏÞÖÆÅÌÎÊЧ¹ûÊýÄ¿

ͨ³£ £¬ÎÒÃDz»ÐèÒªÅÌÎÊËùÓмͼÖеÄÖ¸¶¨×ֶΡ£ÎÒÃÇ¿ÉÒÔʹÓÃlimitÒªÁìÀ´ÏÞÖÆÅÌÎÊЧ¹ûÊýÄ¿¡£ÀýÈç £¬ÎÒÃÇÖ»ÏëÅÌÎÊÇ°10¸öÓû§µÄÓû§Ãû £¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

// ½¨ÉèÒ»¸öUserÄ£×ÓʵÀý
$user = new \app\model\User();
// ÅÌÎÊÇ°10¸öÓû§µÄÓû§Ãû
$usernames = $user->field('username')->limit(10)->select();
// ´òÓ¡Óû§Ãû
foreach ($usernames as $username) {
    echo $username['username'] . "<br/>";
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖÐ £¬ÎÒÃÇʹÓÃlimitÒªÁìÖ¸¶¨ÅÌÎÊЧ¹ûÊýĿΪ10¡£

ÒÔÉϾÍÊÇthinkphpÅÌÎÊÖ¸¶¨×Ö¶ÎÖµµÄÒªÁìÊÇʲôµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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