thinkphp º¯Êý¿âÔÚÄÄ
thinkphp ÊÇÒ»¿î¿ªÔ´µÄ php ¿ò¼Ü¡£ËüÇáÓ¯Ò×ѧ¡¢¿ìËÙ¿ª·¢¡¢ÎÞа¿ÉÀ©Õ¹£¬Òò´Ë±¸ÊܳÌÐòÔ±Çàíù¡£thinkphp ÖаüÀ¨ÖÖÖÖº¯Êý¿â£¬¿ÉÒÔ×ÊÖú¿ª·¢ÕßÌá¸ß¿ª·¢Ð§ÂʺʹúÂëÖÊÁ¿¡£ÄÇô£¬thinkphp º¯Êý¿âÔÚÄÇÀïÄØ£¿±¾Îĸø¸÷ÈËÏê½â¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÃ÷È·Ò»¸ö¿´·¨£ºthinkphp º¯Êý¿â°üÀ¨Á½¸ö²¿·Ö¡£Ò»²¿·ÖÊÇ¿ò¼Ü×Ô´øµÄº¯Êý¿â£¬Î»ÓÚ¿ò¼Ü½¹µã¿âÖУ»ÁíÒ»²¿·ÖÊÇÓû§×Ô½ç˵µÄº¯Êý¿â£¬Î»ÓÚÓ¦ÓÿâÖС£ÏÂÃæÎÒÃǽ«»®·ÖÏÈÈÝÕâÁ½¸öº¯Êý¿âµÄλÖü°Ê¹ÓÃÒªÁì¡£
Ò»¡¢thinkphp ¿ò¼Ü×Ô´øº¯Êý¿â
thinkphp ¿ò¼Ü×Ô´øµÄº¯Êý¿âλÓÚ¿ò¼Ü½¹µã¿âÖУ¬Ö÷Òª´æ·ÅÔÚ thinkPHP/library/think Ŀ¼Ï¡£ÕâЩº¯Êý¿ÉÒÔÀû±ãµØ±»¿ª·¢ÕßŲÓ㬼«´óµØÌá¸ßÁË¿ª·¢Ð§ÂÊ¡£ÏÂÃæÊÇһЩ³£ÓõĿò¼Ü×Ô´øº¯Êý¿â¼°ÆäλÖá£
Êý¾Ý¿â²Ù×÷º¯Êý
thinkphp ¿ò¼Ü×Ô´øµÄÊý¾Ý¿â²Ù×÷º¯Êý¿âλÓÚ thinkPHP/library/think/db Ŀ¼Ï¡£ÕâЩº¯Êý·â×°ÁËÊý¾Ý¿âµÄÔöɾ¸Ä²éµÈ²Ù×÷£¬¿ª·¢Õß¿ÉÒÔÖ±½ÓŲÓÃÕâЩº¯ÊýʵÏÖ¶ÔÊý¾Ý¿âµÄ²Ù×÷¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
»º´æ²Ù×÷º¯Êý
thinkphp ¿ò¼Ü×Ô´øµÄ»º´æ²Ù×÷º¯Êý¿âλÓÚ thinkPHP/library/think/cache Ŀ¼Ï¡£ÕâЩº¯Êý·â×°ÁË»º´æµÄ¶ÁдµÈ²Ù×÷£¬¿ª·¢Õß¿ÉÒÔÖ±½ÓŲÓÃÕâЩº¯ÊýʵÏÖ¶Ô»º´æµÄ²Ù×÷¡£
Îļþ²Ù×÷º¯Êý
thinkphp ¿ò¼Ü×Ô´øµÄÎļþ²Ù×÷º¯Êý¿âλÓÚ thinkPHP/library/think/file Ŀ¼Ï¡£ÕâЩº¯Êý·â×°ÁËÎļþµÄ¶ÁдµÈ²Ù×÷£¬¿ª·¢Õß¿ÉÒÔÖ±½ÓŲÓÃÕâЩº¯ÊýʵÏÖ¶ÔÎļþµÄ²Ù×÷¡£
ͼÏñ²Ù×÷º¯Êý
thinkphp ¿ò¼Ü×Ô´øµÄͼÏñ²Ù×÷º¯Êý¿âλÓÚ thinkPHP/library/think/image Ŀ¼Ï¡£ÕâЩº¯Êý·â×°ÁËͼÏñµÄ¼ô²Ã¡¢Ëõ·Å¡¢Ë®Ó¡µÈ²Ù×÷£¬¿ª·¢Õß¿ÉÒÔÖ±½ÓŲÓÃÕâЩº¯ÊýʵÏÖ¶ÔͼÏñµÄ²Ù×÷¡£
¶þ¡¢thinkphp Ó¦ÓÃ×Ô½ç˵º¯Êý¿â
ÔÚ thinkphp ÖУ¬Óû§Ò²¿ÉÒÔ×Ô½ç˵һЩº¯Êý£¬²¢ÇÒ°ÑÕâЩº¯Êýд³É¿âµÄÐÎʽ£¬ÒÔ±ãÔÚÓ¦ÓóÌÐòÖÐÖظ´Ê¹Óá£ÕâЩº¯Êý¿â´æ·ÅÓÚÓ¦ÓÿâÖУ¬ÒÔÏÂÒÔÒ»¸öʾÀýÀ´ÏÈÈÝÕâÀຯÊý¿âµÄλÖü°Ê¹ÓÃÒªÁì¡£
ÀýÈ磬ÎÒÃÇ×Ô½ç˵һ¸öº¯Êý¿â db.func.php£¬´æ·ÅÓÚÓ¦ÓÃĿ¼Ï嵀 common Ŀ¼Ï£¬ËüµÄ·¾¶Îª application/common/db.func.php¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý£º
<?php //ÅþÁ¬Êý¾Ý¿â function dbConnect(){ $db = new \Think\Db\Connection(config('DB_TYPE').':host='.config('DB_HOST').';dbname='.config('DB_NAME'), config('DB_USER'), config('DB_PWD')); return $db; } //ÅÌÎʵ¥ÌõÊý¾Ý function dbFind($table, $where){ $db = dbConnect(); $result = $db->table($table)->where($where)->find(); return $result; } //ÅÌÎʶàÌõÊý¾Ý function dbSelect($table, $where, $order, $limit){ $db = dbConnect(); $result = $db->table($table)->where($where)->order($order)->limit($limit)->select(); return $result; } //²åÈëÊý¾Ý function dbInsert($table, $data){ $db = dbConnect(); $result = $db->table($table)->insert($data); return $result; } //¸üÐÂÊý¾Ý function dbUpdate($table, $data, $where){ $db = dbConnect(); $result = $db->table($table)->where($where)->update($data); return $result; } //ɾ³ýÊý¾Ý function dbDelete($table, $where){ $db = dbConnect(); $result = $db->table($table)->where($where)->delete(); return $result; } ?>
µÇ¼ºó¸´ÖÆ
ÉÏÊöʾÀý½ç˵ÁËһЩ³£ÓõÄÊý¾Ý²Ù×÷º¯Êý£¬°üÀ¨ÅþÁ¬Êý¾Ý¿â¡¢ÅÌÎʵ¥ÌõÊý¾Ý¡¢ÅÌÎʶàÌõÊý¾Ý¡¢²åÈëÊý¾Ý¡¢¸üÐÂÊý¾ÝºÍɾ³ýÊý¾Ý¡£Ê¹ÓÃÕâ¸ö×Ô½ç˵º¯Êý¿âµÄÒªÁìºÜ¼òÆÓ£¬Ö»ÐèÒªÔÚÐèҪʹÓÃÕâЩº¯ÊýµÄµØ·½ÒýÈë db.func.php Îļþ¼´¿É£¬ÈçÏÂÃæµÄʾÀý£º
<?php require_once(APP_PATH.'/common/db.func.php'); //ÅÌÎʵ¥ÌõÊý¾Ý $result = dbFind('user', 'id=1'); //ÅÌÎʶàÌõÊý¾Ý $result = dbSelect('user', 'id>0', 'id desc', '0,10'); //²åÈëÊý¾Ý $data = array('name'=>'Tom','age'=>23,'sex'=>'ÄÐ'); $result = dbInsert('user', $data); //¸üÐÂÊý¾Ý $data = array('name'=>'Jerry','age'=>24,'sex'=>'Å®'); $result = dbUpdate('user', $data, 'id=1'); //ɾ³ýÊý¾Ý $result = dbDelete('user', 'id=1'); ?>
µÇ¼ºó¸´ÖÆ
ͨ¹ýÉÏÊöʾÀý¿ÉÒÔ¿´³ö£¬Ê¹ÓÃ×Ô½ç˵º¯Êý¿â¿ÉÒÔ´ó´ó¼ò»¯´úÂ룬Ìá¸ß¿ª·¢Ð§ÂÊ¡£Òò´Ë£¬±àд×Ô½ç˵º¯Êý¿âÊÇ thinkphp ¿ª·¢Öв»¿É»òȱµÄÒ»²¿·Ö¡£
±¾ÎÄËùÏÈÈݵÄÊÇ thinkphp º¯Êý¿âÔÚÄÄ£¬ÒÔ¼°¿ò¼Ü×Ô´øº¯Êý¿âºÍÓ¦ÓÃ×Ô½ç˵º¯Êý¿âµÄʹÓÃÒªÁ졣ͨ¹ý±¾ÎĵÄÏÈÈÝ£¬ÐÅÍи÷ÈË¶Ô thinkphp º¯Êý¿âÓÐÁ˸üÉîÈë¡¢¸üÖÜÈ«µÄÊìϤ£¬Ò²ÄܸüºÃµØʹÓÃÕâ¸ö PHP ¿ò¼Ü¡£
ÒÔÉϾÍÊÇthinkphp º¯Êý¿âÔÚÄĵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡