尊龙凯时人生就是博

ÔÚThinkPHP¿ò¼ÜÏÂÔõô¾ÙÐÐÔöɾ¸Ä²Ù×÷

Ò»¡¢ÔöÌí¼Í¼

ÔÚThinkPHPÖÐÐÂÔöÒ»Ìõ¼Í¼£¬ÐèҪʹÓÃÄ£×ӺͿØÖÆÆ÷ ¡£Ê×ÏÈ£¬ÐèÒªÔÚÄ£×ÓÖнç˵±íÃûÒÔ¼°×Ö¶ÎÐÅÏ¢ ¡£ºÃ±È£¬ÔÚÄ£×ÓÖнç˵±íÃûºÍ×Ö¶ÎÐÅÏ¢ºó£¬¾Í¿ÉÒÔÔÚѧÉú±íÖÐÌí¼ÓÒ»Ìõ¼Í¼

class StudentModel extends Model
{
    protected $tableName = 'student';    //±íÃû
    protected $fields = array('id', 'name', 'age', 'sex');    //×Ö¶ÎÐÅÏ¢
}

µÇ¼ºó¸´ÖÆ

È»ºó£¬ÔÚ¿ØÖÆÆ÷Öн¨ÉèÒ»¸öStudent¹¤¾ß£¬²¢Ö¸¶¨ÒªÌí¼ÓµÄÊý¾Ý£º

public function add()
{
    $student = D('Student');    //ʵÀý»¯Student¹¤¾ß
    $data = array(
        'name' => 'Tom',
        'age' => 18,
        'sex' => 'ÄÐ'
    );    //ÒªÌí¼ÓµÄÊý¾Ý
    $student->add($data);    //Ìí¼ÓÊý¾Ý
}

µÇ¼ºó¸´ÖÆ

¶þ¡¢É¾³ý¼Í¼

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

ÔÚThinkPHPÖÐɾ³ýÒ»Ìõ¼Í¼£¬ÐèҪʹÓÃÄ£×ӺͿØÖÆÆ÷ ¡£ÔÚ¿ØÖÆÆ÷ÖУ¬½¨ÉèÒ»¸öÃûΪStudentµÄ¹¤¾ß£¬È»ºóͨ¹ýÖ¸¶¨ÒªÉ¾³ýµÄID£¬À´É¾³ýÏìÓ¦µÄ¼Í¼

public function delete()
{
    $id = 1;    //Ҫɾ³ýµÄ¼Í¼µÄID
    $student = D('Student');    //ʵÀý»¯Student¹¤¾ß
    $student->delete($id);    //Ö´ÐÐɾ³ý²Ù×÷
}

µÇ¼ºó¸´ÖÆ

ThinkPHPµÄɾ³ýÒªÌå»á×Ô¶¯Æ¾Ö¤Ö÷¼üɾ³ýÊý¾Ý£¬ÈôÊÇÐèҪƾ֤ÆäËûÌõ¼þɾ³ý¼Í¼£¬Ôò¿ÉÒÔÔÚdeleteÒªÁìÖд«ÈëÒ»¸öÊý×é×÷ΪµÚ¶þ¸ö²ÎÊý£¬ÀýÈ磺

public function delete()
{
    $condition = array('age' => array('gt', 18));    //ɾ³ýÖª×ãÌõ¼þµÄ¼Í¼£¨ÄêËê´óÓÚ18ËêµÄ¼Í¼£©
    $student = D('Student');    //ʵÀý»¯Student¹¤¾ß
    $student->where($condition)->delete();    //Ö´ÐÐɾ³ý²Ù×÷
}

µÇ¼ºó¸´ÖÆ

Èý¡¢Ð޸ļͼ

ÔÚThinkPHPÖÐÐÞ¸ÄÒ»Ìõ¼Í¼£¬Í¬ÑùÐèҪʹÓÃÄ£×ӺͿØÖÆÆ÷ ¡£Ê×ÏÈ£¬½¨ÉèÒ»¸öÃûΪStudentµÄ¹¤¾ß£¬È»ºóÔÚ¿ØÖÆÆ÷ÖÐƾ֤ҪÐ޸ĵļͼµÄID¾ÙÐÐÐ޸IJÙ×÷

public function update()
{
    $id = 1;    //ÒªÐ޸ĵļͼµÄID
    $student = D('Student');    //ʵÀý»¯Student¹¤¾ß
    $data = array(
        'name' => 'Jerry',
        'age' => 20,
        'sex' => 'ÄÐ'
    );    //ÒªÐ޸ĵÄÊý¾Ý

    $student->where(array('id' => $id))->save($data);    //Ö´ÐÐÐ޸IJÙ×÷
}

µÇ¼ºó¸´ÖÆ

ÔÚsaveÒªÁìÖУ¬¿ÉÒÔÑ¡ÔñÊÇ·ñÓõÚÒ»¸ö²ÎÊýÀ´Ö¸¶¨ÒªÐ޸ĵļͼµÄÌõ¼þ ¡£ÈôÊDz»Ö¸¶¨£¬Ôò»áƾ֤Ö÷¼ü¾ÙÐÐÐÞ¸Ä ¡£

ÒÔÉϾÍÊÇÔÚThinkPHP¿ò¼ÜÏÂÔõô¾ÙÐÐÔöɾ¸Ä²Ù×÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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