×ðÁú¿­Ê±

thinkphp3.2ÔõÑùÔöÌíÊý¾Ý¿âÉèÖò¢²Ù×÷Êý¾Ý

Ò»¡¢Êý¾Ý¿âÉèÖÃ

ÔÚconfigÎļþ¼ÐÖÐн¨database.phpÎļþ£¬Ìí¼ÓÒÔÏÂÉèÖãº

return array(
    'DB_TYPE'               =>  'mysql',    // Êý¾Ý¿âÀàÐÍ
    'DB_HOST'               =>  'localhost', // ЧÀÍÆ÷µØµã
    'DB_NAME'               =>  'dbname',   // Êý¾Ý¿âÃû
    'DB_USER'               =>  'username',   // ̞
    'DB_PWD'                =>  'password',   // ÃÜÂë
    'DB_PORT'               =>  '3306',   // ¶Ë¿Ú
    'DB_PREFIX'             =>  '',    // Êý¾Ý¿â±íǰ׺
);

µÇ¼ºó¸´ÖÆ

ÐÞ¸ÄÊý¾Ý¿âÉèÖá£ÔÚÉèÖÃÎļþconfig.phpÖмÓÈëÒÔÏ´úÂ룺

// Êý¾Ý¿âÉèÖÃÐÅÏ¢
'DB_CONFIG1' => include 'database.php',

µÇ¼ºó¸´ÖÆ

ͨ¹ýÒÔÉÏÉèÖã¬ÎÒÃǽ«Êý¾Ý¿âÉèÖÃÎļþdatabase.phpÌí¼Óµ½ÁËconfig.phpÖУ¬²¢ÉèÖÃÁËÊý¾Ý¿âµÄÅþÁ¬²ÎÊý¡£

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

¶þ¡¢Êý¾Ý¿âÅþÁ¬

ÔÚmodelÎļþ¼ÐÖÐн¨PublicModel.class.phpÎļþ£¬Ìí¼ÓÒÔÏ´úÂ룺

<?php
namespace Model;
use Think\Model;
class PublicModel extends Model {
    protected $db_config    =   'DB_CONFIG1';
}

µÇ¼ºó¸´ÖÆ

ͨ¹ýÒÔÉÏ´úÂ룬ÎÒÃǽ¨ÉèÁËÒ»¸öPublicModelÀà¼ÌÐø×ÔThinkPHPÌṩµÄModelÀ࣬¶ø$db_config±äÁ¿Ö¸Ã÷ÎúÅþÁ¬µÄÉèÖá£

Êý¾Ý¿âÅþÁ¬Ê¹Óá£ÔÚ¿ØÖÆÆ÷ÖпÉÒÔÖ±½ÓʹÓÃPublicModelÀ࣬ʹÓÃÒªÁìÈçÏ£º

$PublicModel = M('Public');

µÇ¼ºó¸´ÖÆ

ÎÒÃÇʹÓÃMº¯ÊýŲÓÃPublicModelÄ£×Ó£¬´Ó¶ø½¨ÉèÁËÒ»¸öPublicModel¹¤¾ß¡£ÕâÑùÎÒÃǾͽ¨ÉèÁËÅþÁ¬µ½Êý¾Ý¿âµÄÅþÁ¬¡£

Èý¡¢Êý¾Ý²Ù×÷

ÔÚÅþÁ¬ÁËÊý¾Ý¿âÖ®ºó£¬ÎÒÃÇ»¹ÐèÒª¾ÙÐÐÊý¾Ý²Ù×÷£¬°üÀ¨ÔöÌí¡¢Ð޸ĺÍɾ³ýµÈ²Ù×÷¡£ÏÂÃæ»®·ÖÏÈÈÝÕâЩ²Ù×÷¡£

Êý¾ÝÅÌÎÊ

$PublicModel = M('Public');
$list = $PublicModel->where('id=1')->find();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂë¶ÔPublicModelÄ£×Ó¾ÙÐÐÁËÒ»´ÎÅÌÎÊ£¬²¢½«idΪ1µÄ¼Í¼·µ»Ø¡£

Êý¾Ý²åÈë

$PublicModel = M('Public');
$data['username'] = 'tom';
$data['password'] = '123456';
$id = $PublicModel->add($data);

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂë¶ÔPublicModelÄ£×Ó¾ÙÐÐÁËÒ»´Î²åÈë²Ù×÷£¬½«Óû§ÃûΪtom£¬ÃÜÂëΪ123456µÄ¼Í¼²åÈëµ½Êý¾Ý¿â£¬²¢·µ»Ø²åÈëµÄ¼Í¼IDºÅ¡£

Êý¾ÝÐÞ¸Ä

$PublicModel = M('Public');
$data['username'] = 'tom';
$map['id'] = 1;
$result = $PublicModel->where($map)->save($data);

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂë¶ÔPublicModelÄ£×Ó¾ÙÐÐÁËÒ»´ÎÐ޸IJÙ×÷£¬½«idΪ1µÄ¼Í¼µÄÓû§Ãû¸ÄΪtom£¬²¢·µ»Ø²Ù×÷Ч¹û¡£

Êý¾Ýɾ³ý

$PublicModel = M('Public');
$map['id'] = 1;
$result = $PublicModel->where($map)->delete();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂë¶ÔPublicModelÄ£×Ó¾ÙÐÐÁËÒ»´Îɾ³ý²Ù×÷£¬É¾³ýidΪ1µÄ¼Í¼£¬²¢·µ»Ø²Ù×÷Ч¹û¡£

ÒÔÉϾÍÊÇthinkphp3.2ÔõÑùÔöÌíÊý¾Ý¿âÉèÖò¢²Ù×÷Êý¾ÝµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

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

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

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