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

thinkphp¿ò¼ÜÔõôÉèÖöà¸ö×Ö¶Î

thinkphp¿ò¼ÜÊÇÒ»¸öÊ¢ÐеÄphp¿ª·¢¿ò¼Ü£¬ËüÌṩÁËÇ¿Ê¢µÄ¹¦Ð§ºÍÒ×ÓÚʹÓõĽӿÚ£¬×ÊÖú¿ª·¢Ö°Ô±¿ìËÙ¹¹½¨¸ßÖÊÁ¿µÄwebÓ¦ÓóÌÐò¡£ÔÚÓ¦ÓóÌÐò¿ª·¢ÖУ¬¾­³£ÐèÒªÉèÖöà¸ö×Ö¶ÎÒÔÖª×ã²î±ðµÄÐèÇó¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÔÚthinkphp¿ò¼ÜÖÐÉèÖöà¸ö×ֶΡ£

1.ÔÚÄ£×ÓÖÐÉèÖöà¸ö×Ö¶Î

ÔÚThinkPHP¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔÔÚÄ£×ÓÖÐÉèÖöà¸ö×ֶΣ¬ÒÔ±ãÔÚÊý¾Ý¿âÖд洢²î±ðÀàÐ͵ÄÊý¾Ý¡£¿ÉÒÔͨ¹ýÉèÖÃ$pkÊôÐÔÀ´Ö¸¶¨Ä£×ÓµÄÖ÷¼ü×ֶΣ¬¿ÉÒÔͨ¹ýÉèÖÃ$tableNameÊôÐÔÀ´Ö¸¶¨Ä£×Ó¹ØÁªµÄÊý¾Ý±íÃû¡£

˼Á¿ÒÔÏÂÄ£×Ó´úÂëʾÀý£º

namespace appindexmodel;

use thinkModel;

class User extends Model
{
    protected $pk = 'id';
    protected $tableName = "user";
    protected $autoWriteTimestamp = true;
    protected $createTime = "create_time";
    protected $updateTime = "update_time";

    protected $userName = "user_name";
    protected $userAge = "user_age";
}

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸öUserÄ£×Ó£¬ÆäÖаüÀ¨ÁË$pk¡¢$tableName¡¢$autoWriteTimestamp¡¢$createTime¡¢$updateTime¡¢$userNameºÍ$userAgeÊôÐÔ¡£

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

ÆäÖУ¬$userNameºÍ$userAgeÊôÐÔÌåÏÖUserÄ£×Ó°üÀ¨µÄÁ½¸ö×ֶΡ£ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂëÀ´ÉèÖúͻñÈ¡ÕâÁ½¸ö×ֶεÄÖµ£º

$user = new User;

// ÉèÖÃuserNameºÍuserAge×ֶεÄÖµ
$user->userName = 'Tom';
$user->userAge = 25;

// ÉúÑÄÓû§
$user->save();

// »ñÈ¡Óû§ÃûºÍÄêËê
$username = $user->userName;
$userage = $user->userAge;

µÇ¼ºó¸´ÖÆ

2.ʹÓÃÊý¾Ý¿âǨáãÉèÖöà¸ö×Ö¶Î

ʹÓÃÊý¾Ý¿âǨáã¿ÉÒÔÇáËɵØÔÚÊý¾Ý¿âÖн¨Éè±íºÍ×ֶΡ£ÔÚThinkPHP¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÊý¾Ý¿âǨáãʵÏÖÅúÁ¿µØÌí¼ÓºÍÐ޸ıíºÍ×ֶΡ£

ÒÔÏÂÊÇÒ»¸öʹÓÃÊý¾Ý¿âǨáãÉèÖöà¸ö×ֶεĴúÂëʾÀý£º

use thinkmigrationdbColumn;
use thinkmigrationMigrator;

class CreateUserTable extends Migrator
{
    public function up()
    {
        $table = $this->table('user');
        $table->addColumn('user_name', 'string', ['default' => '', 'comment' => '̞'])
              ->addColumn('user_age', 'integer', ['default' => 0, 'comment' => 'ÄêËê'])
              ->addColumn('create_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '½¨Éèʱ¼ä'])
              ->addColumn('update_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '¸üÐÂʱ¼ä'])
              ->create();
    }

    public function down()
    {
        $this->dropTable('user');
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏʾÀýÖУ¬ÎÒÃÇʹÓÃÁËthink-migrationÀ©Õ¹°üÀ´ÊµÏÖÊý¾ÝǨáã¡£

ʹÓÃaddColumnÒªÁì¿ÉÒÔÌí¼Ó¶à¸ö×ֶΣ¬ÆäÖÐÿ¸ö×ֶζ¼ÓÐÆäÀàÐÍ¡¢Ä¬ÈÏÖµºÍ×¢ÊÍ¡£Í¨¹ýcreateÒªÁì¿ÉÒÔ½¨ÉèÊý¾Ý±í¡£

×ܽá

ÔÚThinkPHP¿ò¼ÜÖÐÉèÖöà¸ö×Ö¶ÎÊǺÜÊǼòÆӵġ£ÎÒÃÇ¿ÉÒÔÔÚÄ£×ÓÖÐÖ±½ÓÉèÖöà¸ö×ֶΣ¬ÔÚÊý¾Ý¿âǨáãÖÐÅúÁ¿µØ½¨Éè±íºÍ×ֶΣ¬ÔÚÓ¦ÓóÌÐòÖÐʹÓÃÕâЩ×ֶΡ£Í¨¹ýÕâЩҪÁ죬ÎÒÃÇ¿ÉÒÔÇáËɵع¹½¨ÇкÏÐèÇóµÄÊý¾Ý½á¹¹£¬ÎªÎÒÃǵÄÓ¦ÓóÌÐòÌṩ¸üºÃµÄÖ§³Ö¡£

ÒÔÉϾÍÊÇthinkphp¿ò¼ÜÔõôÉèÖöà¸ö×ֶεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ