尊龙凯时人生就是博

thinkphpÔõÑùÐÞ¸ÄÊý¾Ý¿â

Ò»¡¢ThinkPHPÊý¾Ý¿â²Ù×÷

ÔÚThinkPHPÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýËüÌṩµÄÊý¾Ý¿â²Ù×÷ÀàÀ´¾ÙÐжÔÊý¾Ý¿âµÄ²Ù×÷¡£³£ÓõÄÊý¾Ý¿â²Ù×÷ÀàÓУº

DbÀà

ÔÚThinkPHPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃDbÀàÀ´¾ÙÐжÔÊý¾Ý¿âµÄÔö¡¢É¾¡¢¸Ä¡¢²éµÈ²Ù×÷¡£ÆäʹÓÃʾÀýÈçÏ£º

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

<?php
use think\Db;

// ÅÌÎÊÊý¾Ý
$list = Db::table('user')->where('id', 1)->find();

// ÐÂÔöÊý¾Ý
$data['name'] = 'test';
$data['age'] = 20;
Db::table('user')->insert($data);

// ¸üÐÂÊý¾Ý
$where['id'] = 1;
$data['name'] = 'test';
$data['age'] = 30;
Db::table('user')->where($where)->update($data);

// ɾ³ýÊý¾Ý
$where['id'] = 1;
Db::table('user')->where($where)->delete();

µÇ¼ºó¸´ÖÆ

ModelÀà

ÔÚThinkPHPÖÐ £¬ModelÀà¼ÌÐø×ÔDbÀà £¬Òò´ËModelÀà¿ÉÒÔʹÓÃDbÀàµÄËùÓÐÒªÁì £¬Í¬Ê±»¹ÌṩÁËһЩԽ·¢Àû±ãµÄÒªÁì¡£ÆäʹÓÃʾÀýÈçÏ£º

<?php
namespace app\index\model;

use think\Model;

class User extends Model
{
    // ÅÌÎÊÊý¾Ý
    public function getUserById($id)
    {
        return $this->where('id', $id)->find();
    }

    // ¸üÐÂÊý¾Ý
    public function updateUser($id, $name)
    {
        return $this->save(['name' => $name], ['id' => $id]);
    }
}

µÇ¼ºó¸´ÖÆ

¶þ¡¢ThinkPHPÔõÑùÐÞ¸ÄÊý¾Ý¿â

ÔÚʹÓÃThinkPHPÐÞ¸ÄÊý¾Ý¿âʱ £¬Í¨³£»á¾­ÓÉÒÔϼ¸¸ö°ì·¨£º

½¨ÉèÄ£×Ó

ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÄ£×Ó £¬¸ÃÄ£×Ó¶ÔÓ¦×ÅÎÒÃÇÐèÒª»á¼ûµÄÊý¾Ý¿â±í¡£ÓÉÓÚThinkPHP½ÓÄÉÁËMVCÉè¼Æģʽ £¬Òò´ËÎÒÃÇÔÚ½¨ÉèÄ£×ÓʱÐèÒª¼ÌÐø×ÔThinkPHPµÄModelÀà¡£ÏÂÃæÊÇÒ»¸ö½¨ÉèUserÄ£×ÓµÄʾÀý£º

<?php
namespace app\index\model;

use think\Model;

class User extends Model
{
    protected $table = 'user';
    protected $pk = 'id';
}

µÇ¼ºó¸´ÖÆ

ÔÚ½¨ÉèUserÄ£×Óʱ £¬ÎÒÃÇÖ¸¶¨Á˸ÃÄ£×Ó¶ÔÓ¦µÄÊý¾Ý¿â±íÊÇuser±í £¬²¢ÇҸñíµÄÖ÷¼üÊÇid¡£

ʵÀý»¯Ä£×Ó

½ÓÏÂÀ´ £¬ÎÒÃÇÐèҪʹÓÃÏÈÇ°½¨ÉèµÄUserÄ£×Ó¾ÙÐÐʵÀý»¯ £¬²¢Ê¹ÓøÃÄ£×Ó²Ù×÷Êý¾Ý¿â¡£ÏÂÃæÊÇʵÀý»¯UserÄ£×ÓµÄʾÀý£º

<?php
$userModel = new \app\index\model\User();

µÇ¼ºó¸´ÖÆ

ÐÞ¸ÄÊý¾Ý

Ò»µ©½¨ÉèÁËUserÄ£×ÓµÄʵÀý £¬¾Í¿ÉÒÔʹÓøÃÄ£×ÓËùÌṩµÄº¯Êý¶ÔÊý¾Ý¿â¾ÙÐÐÐ޸ġ£ÏÂÃæÊÇÒ»¸öʹÓÃUserÄ£×ÓÐÞ¸ÄÊý¾ÝµÄʾÀý£º

<?php
$userModel = new \app\index\model\User();

// ¸üÐÂÊý¾Ý
$where['id'] = 1;
$data['name'] = 'test';
$data['age'] = 30;
$userModel->where($where)->update($data);

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏʾÀýÖÐ £¬ÎÒÃÇʹÓÃ$UserModelµÄupdate()ÒªÁì¶ÔUser±íÖÐidΪ1µÄÊý¾Ý¾ÙÐÐÁËÐÞ¸Ä £¬½«¸ÃÐÐÊý¾ÝµÄname×Ö¶ÎÐÞ¸ÄΪtest £¬age×Ö¶ÎÐÞ¸ÄΪ30¡£

ÒÔÉϾÍÊÇthinkphpÔõÑùÐÞ¸ÄÊý¾Ý¿âµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

13452372176

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

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

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