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

ʵÀý½â˵ThinkPHPÖеÄÔöɾ¸Ä²é²Ù×÷

thinkphpÊÇÒ»¿îÓÅÒìµÄphp¿ò¼Ü £¬ËüµÄ½¹µãÌصãÊÇÇáÁ¿¿ìËÙ £¬ÒÔ¼°Ç¿Ê¢µÄ¼ò»¯±à³Ì £¬Ìá¸ß¿ª·¢Ð§ÂÊ¡£ÆäÖÐ £¬×îΪÖ÷ÒªµÄËĸö²Ù×÷ÊÇÔö¡¢É¾¡¢¸Ä¡¢²é £¬Ò²¾ÍÊÇ crud £¬½ÓÏÂÀ´½«ÍŽáÏÖʵ¿ª·¢°¸ÀýÀ´ÏÈÈÝthinkphpÖеÄÔöɾ¸Ä²é²Ù×÷¡£

Ò»¡¢ÔöÌí

Êý¾ÝµÄÐÂÔöÊÇÎÒÃÇÔÚThinkPHPÖÐʹÓÃ×îƵÈԵIJÙ×÷Ö®Ò»¡£ÔÚTPÖÐ £¬ÐÂÔöÊý¾Ý¿ÉÒÔʹÓÃTPµÄmodelÀà¿âÖеÄÒ»¸öÒªÁì £¬Í¨¹ýʵÀý»¯Ä£×ÓÀàÀ´¾ÙÐÐÊý¾Ý²åÈë¡£ÒÔÏÂÊÇÒ»¸öͨÀýÒªÁ죺

$data = [
    'name' => 'ÕÅÈý',
    'age' => '18',
    'gender' => 'ÄÐ'
];
$model = new UserModel;
$res = $model->save($data);

µÇ¼ºó¸´ÖÆ

Õâ¶Î´úÂëµÄ¼ÄÒåÊÇÏò¡°User¡±±íÖÐдÈëÒ»ÌõÊý¾Ý £¬Êý¾ÝΪnameΪ¡®ÕÅÈý¡¯ £¬ageΪ¡®18¡¯ £¬genderΪ¡®ÄС¯¡£ÆäÖÐ £¬UserModelÊÇÎÒÃÇÊÂÏȽ¨ÉèµÄÄ£×ÓÎļþ £¬Ëü¼ÌÐøÁËThinkPHPµÄModelÀà £¬È»ºó¾ÙÐÐÁËÏà¹ØÉèÖúͽç˵¡£saveÒªÌå»á·µ»Ø²¼¶ûÖµ £¬´ú±íÊÇ·ñдÈëÀֳɡ£

ÔÚÏÖʵ¿ª·¢ÖÐ £¬ÎÒÃǾ­³£»áÓöµ½Ò»´ÎÐÔ²åÈë¶àÌõÊý¾ÝµÄÇéÐΡ£ÔÚTPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃTPÌṩµÄÅúÁ¿²åÈëµÄÒªÁì £¬Ïêϸ´úÂëÈçÏ£º

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

$data = [
    [
        'name' => 'ÕÅÈý',
        'age' => '18',
        'gender' => 'ÄÐ'
    ],
    [
        'name' => 'ÀîËÄ',
        'age' => '22',
        'gender' => 'ÄÐ'
    ],
    [
        'name' => 'Lucy',
        'age' => '20',
        'gender' => 'Å®'
    ]
];
$model = new UserModel;
$res = $model->saveAll($data);

µÇ¼ºó¸´ÖÆ

¶þ¡¢É¾³ý

Êý¾ÝµÄɾ³ýÊÇÎÒÃÇÔÚºǫ́ÖÎÀíϵͳÖо­³£Óöµ½µÄ²Ù×÷Ö®Ò»¡£ÔÚTPÖÐ £¬É¾³ýÊý¾ÝÒ²ÊÇͨ¹ýÄ£×ÓÀàÀ´ÊµÏֵġ£ÎÒÃÇ¿ÉÒÔʹÓÃdeleteÒªÁìÀ´É¾³ýÒ»Ìõ»òÕ߶àÌõÊý¾Ý¡£deleteÒªÁìµÄʹÓ÷½·¨¿ÉÒÔÊÇÖ±½Óͨ¹ýÖ÷¼üÀ´²Ù×÷ £¬Ò²¿ÉÒÔÊÇʹÓÃÌõ¼þ£¨Ò²¾ÍÊÇwhere£©À´É¸Ñ¡Êý¾Ý¡£

// É¾³ýÒ»ÌõÊý¾Ý
$model = new UserModel;
$res = $model->where(['id' => 1])->delete();

// É¾³ý¶àÌõÊý¾Ý
$model = new UserModel;
$ids = '1,2,3';
$res = $model->where(['id' => ['in', $ids]])->delete();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëµÄ¼ÄÒåÊÇ´ÓUser±íÖÐɾ³ýidΪ1µÄÊý¾Ý £¬»òÕßɾ³ýidΪ1¡¢2¡¢3µÄÊý¾Ý¡£

Èý¡¢ÐÞ¸Ä

Êý¾ÝµÄÐÞ¸ÄÊÇÎÒÃǾÙÐÐÓªÒµÂß¼­´¦Àíʱ¾­³£Óõ½µÄ²Ù×÷¡£TPÌṩÁËupdateÒªÁìÀ´ÊµÏÖÊý¾ÝµÄÐ޸ġ£updateÒªÁìÒ²¿ÉÒÔÖ±½Óͨ¹ýÖ÷¼üÀ´²Ù×÷ £¬Ò²¿ÉÒÔʹÓÃÌõ¼þÀ´É¸Ñ¡Êý¾Ý¡£

// ÐÞ¸ÄÒ»ÌõÊý¾Ý
$model = new UserModel;
$data = [
    'name' => 'ÕÅÈý',
    'age' => '20',
    'gender' => 'ÄÐ'
];
$res = $model->where(['id' => 1])->update($data);

// Ð޸ĶàÌõÊý¾Ý
$model = new UserModel;
$data = [
    'gender' => 'Å®'
];
$ids = '2,3,4';
$res = $model->where(['id' => ['in', $ids]])->update($data);

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëÊǽ«User±íÖÐidΪ1µÄÊý¾ÝµÄname¸ÄΪ¡®ÕÅÈý¡¯ £¬age¸ÄΪ¡®20¡¯ £¬gender¸ÄΪ¡®ÄС¯¡£´Ëºó¶Î´úÂëµÄ¼ÄÒåÊǽ«idΪ2¡¢3¡¢4µÄÊý¾ÝµÄgender¸ÄΪ¡®Å®¡¯¡£

ËÄ¡¢ÅÌÎÊ

Êý¾ÝµÄÅÌÎÊÊÇÎÒÃÇ×î³£ÓõIJÙ×÷Ö®Ò»¡£ÔÚTPÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃmodelÀïµÄselectÒªÁì¡¢findÒªÁì¡¢getFieldÒªÁìµÈÒªÁì¾ÙÐÐÊý¾ÝµÄÅÌÎÊ¡£³£ÓõÄÅÌÎÊ·½·¨ÈçÏ£º

// ÅÌÎÊËùÓÐÊý¾Ý
$model = new UserModel;
$res = $model->select();

// ÅÌÎÊÒ»ÌõÊý¾Ý
$model = new UserModel;
$res = $model->where(['id' => 1])->find();

//ÅÌÎÊÖ¸¶¨×Ö¶Î
$model = new UserModel;
$res = $model->getField('id,name,age');

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëµÄ¼ÄÒåÊÇÅÌÎÊUser±íÖеÄËùÓÐÊý¾Ý £¬»òÕßÅÌÎÊidΪ1µÄÊý¾Ý £¬»òÕßÅÌÎÊid¡¢nameºÍage×ֶΡ£ÕâÀïÐèҪעÖصÄÊÇ £¬ÔÚʹÓÃgetFieldÒªÁìʱ £¬·µ»ØµÄЧ¹ûÊÇÒ»¸öÒÔidΪkey £¬name¡¢ageΪvalueµÄÊý×é¡£ÈôÒªÐÞ¸Äkey»òÐÞ¸ÄÒÔÆäËû×Ö¶ÎΪvalue £¬ÐèҪͨ¹ýtpµÄÊý×麯Êý¾ÙÐмӹ¤´¦Àí¡£

×ܽ᣺

×ÛÉÏËùÊö £¬CRUDÔÚTPÖÐÊÇÒ»¸ö·Ç¾­³£¼ûµÄ²Ù×÷¡£ÕÆÎÕÕâËĸö²Ù×÷¿ÉÒÔʹÎÒÃÇÔ½·¢Àû±ã¿ì½ÝµØ¾ÙÐкǫ́ӪҵÂß¼­´¦Àí¡£ËäÈ» £¬TPÕë¶ÔÕ⼸¸ö²Ù×÷ÉÐÓÐÆäËû¸ü¶àµÄÒªÁì £¬Ï£Íû¸÷ÈËÔÚѧϰÀú³ÌÖÐÄܹ»½øÒ»²½Ì½ÌÖ £¬²¢ÉîÈëÃ÷È·Æäµ×²ãÔ­Àí¡£ÊÂʵ £¬ÕÆÎÕºÃÔöɾ¸Ä²é £¬²ÅÊÇÕæµÄÄܹ»°ÑTPÔËÓõ½µ½¼«ÖµÄÒªº¦¡£

ÒÔÉϾÍÊÇʵÀý½â˵ThinkPHPÖеÄÔöɾ¸Ä²é²Ù×÷µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ