亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 41
粉絲 2
評(píng)論 0
訪問(wèn)量 36639
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
php之?dāng)?shù)據(jù)庫(kù)鏈?zhǔn)讲僮?/div>
月光下,遺忘黑暗
原創(chuàng)
1289人瀏覽過(guò)

代碼塊

<?php/** * 事件委托 : 數(shù)據(jù)庫(kù)查詢構(gòu)造器 * Db::table()->field()->where()->limit()->select()->toArray(); *  */ //被委托的類class Query{    protected $db;//pdo連接對(duì)象    protected $table;    protected $field;    protected $limit;    protected $value;    //連接數(shù)據(jù)庫(kù)    private function connect($dsn,$username,$password)    {        $this->db = new PDO($dsn,$username,$password);    }    function __construct($dsn,$username,$password)    {        $this->connect($dsn,$username,$password);    }    //數(shù)據(jù)表方法    public function table($table)    {        $this->table = $table;        return $this;    }    public function field($field)    {        $this->field = $field;        return $this;    }    public function limit($limit)    {        $this->limit = $limit;        return $this;    }    public function value($value)    {        $this->value = $value;        return $this;    }    public function getSql()    {        return sprintf('INSERT INTO %s (%s) VALUE(%s)',$this->table,$this->field,$this->value);    }    //執(zhí)行查詢    public function select()    {        return $this->db->query($this->getSql())->fetchAll(PDO::FETCH_ASSOC);    }    public function insert()    {         return $this->db->exec($this->getSql());     }}//工作類class Db{    static function __callStatic($method,$args)    {        $dsn = 'mysql:host=localhost;dbname=video';        $username = 'root';        $password = 'root';        $query = new Query($dsn,$username,$password);        //直接委托給Query類中的具體方法完成        return call_user_func([$query,$method],...$args);    }}$res = Db::table('admins')->field('username,password,truename,gid,add_time')->value("'aaa',321,'fdsaf',1,52342")->insert();echo '<pre>';print_r($res);

效果

批改老師:滅絕師太滅絕師太

批改狀態(tài):合格

老師批語(yǔ):
本博文版權(quán)歸博主所有,轉(zhuǎn)載請(qǐng)注明地址!如有侵權(quán)、違法,請(qǐng)聯(lián)系admin@php.cn舉報(bào)處理!
全部評(píng)論 文明上網(wǎng)理性發(fā)言,請(qǐng)遵守新聞評(píng)論服務(wù)協(xié)議
0條評(píng)論
作者最新博文
關(guān)于我們 免責(zé)申明 意見(jiàn)反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費(fèi)學(xué)