免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
mysql操作類
<?php/** * Created by JetBrains PhpStorm. * User:JAE * Date: 13-8-13 * Time: 下午5:15 * Blog:http://blog.jaekj.com * QQ:734708094 * 通用數(shù)據(jù)庫操作類 * 版本:V1.1 *//* 數(shù)據(jù)庫配置  return array(    'DB_CONFIG' => array(        //數(shù)據(jù)庫配置        'DB_HOST'=>'127.0.0.1',    //服務(wù)器地址        'DB_NAME' => 'tmp', // 數(shù)據(jù)庫名        'DB_USER' => 'root', // 用戶名        'DB_PWD' => '', // 密碼        'DB_ENCODE'=>'utf8',//編碼        'DB_PREFIX' => 'dmtx_' // 數(shù)據(jù)庫表前綴    )); */class M{    private $link; //數(shù)據(jù)庫連接    private $table; //表名    private $prefix; //表前綴    private $db_config; //數(shù)據(jù)庫配置    /**     * 參數(shù):表名 數(shù)據(jù)庫配置數(shù)組 或 數(shù)據(jù)庫配置文件路徑     * @param $table     * @param string $db_config_arr_path     */    function __construct($table, $db_config_arr_path = 'config.php')    {        if (is_array($db_config_arr_path)) {            $this->db_config = $db_config_arr_path;        } else {            $this->db_config = require($db_config_arr_path);        }        $this->conn();        $this->table = $this->prefix . $table;    }    /**     * 連接數(shù)據(jù)庫     */    private function conn()    {        $db_config = $this->db_config;        $host = $db_config["DB_CONFIG"]["DB_HOST"];        $user = $db_config["DB_CONFIG"]["DB_USER"];        $pwd = $db_config["DB_CONFIG"]["DB_PWD"];        $db_name = $db_config["DB_CONFIG"]["DB_NAME"];        $db_encode = $db_config["DB_CONFIG"]["DB_ENCODE"];        $this->prefix = $db_config["DB_CONFIG"]["DB_PREFIX"];        $this->link = mysql_connect($host, $user, $pwd) or die('數(shù)據(jù)庫服務(wù)器連接錯誤:' . mysql_error());        mysql_select_db($db_name) or die('數(shù)據(jù)庫連接錯誤:' . mysql_error());        mysql_query("set names '$db_encode'");    }    /**     * 數(shù)據(jù)查詢     * 參數(shù):sql條件 查詢字段 使用的sql函數(shù)名     * @param string $where     * @param string $field     * @param string $fun     * @return array     * 返回值:結(jié)果集 或 結(jié)果(出錯返回空字符串)     */    public function select($where = '1', $field = "*", $fun = '')    {        $rarr = array();        if (empty($fun)) {            $sqlStr = "select $field from $this->table where $where";            $rt = mysql_query($sqlStr, $this->link);            while ($rt && $arr = mysql_fetch_assoc($rt)) {                array_push($rarr, $arr);            }        } else {            $sqlStr = "select $fun($field) as rt from $this->table where $where";            $rt = mysql_query($sqlStr, $this->link);            if ($rt) {                $arr = mysql_fetch_assoc($rt);                $rarr = $arr['rt'];            } else {                $rarr = '';            }        }        return $rarr;    }    /**     * 數(shù)據(jù)更新     * 參數(shù):sql條件 要更新的數(shù)據(jù)(字符串 或 關(guān)聯(lián)數(shù)組)     * @param $where     * @param $data     * @return bool     * 返回值:語句執(zhí)行成功或失敗,執(zhí)行成功并不意味著對數(shù)據(jù)庫做出了影響     */    public function update($where, $data)    {        $ddata = '';        if (is_array($data)) {            while (list($k, $v) = each($data)) {                if (empty($ddata)) {                    $ddata = "$k='$v'";                } else {                    $ddata .= ",$k='$v'";                }            }        } else {            $ddata = $data;        }        $sqlStr = "update $this->table set $ddata where $where";        return mysql_query($sqlStr);    }    /**     * 數(shù)據(jù)添加     * 參數(shù):數(shù)據(jù)(數(shù)組 或 關(guān)聯(lián)數(shù)組 或 字符串)     * @param $data     * @return int     * 返回值:插入的數(shù)據(jù)的ID 或者 0     */    public function insert($data)    {        $field = '';        $idata = '';        if (is_array($data) && array_keys($data) != range(0, count($data) - 1)) {            //關(guān)聯(lián)數(shù)組            while (list($k, $v) = each($data)) {                if (empty($field)) {                    $field = "$k";                    $idata = "'$v'";                } else {                    $field .= ",$k";                    $idata .= ",'$v'";                }            }            $sqlStr = "insert into $this->table($field) values ($idata)";        } else {            //非關(guān)聯(lián)數(shù)組 或字符串            if (is_array($data)) {                while (list($k, $v) = each($data)) {                    if (empty($idata)) {                        $idata = "'$v'";                    } else {                        $idata .= ",'$v'";                    }                }            } else {                //為字符串                $idata = $data;            }            $sqlStr = "insert into $this->table values ($idata)";        }        if(mysql_query($sqlStr,$this->link))        {            return mysql_insert_id($this->link);        }        return 0;    }    /**     * 數(shù)據(jù)刪除     * 參數(shù):sql條件     * @param $where     * @return bool     */    public function delete($where)    {        $sqlStr = "delete from $this->table where $where";        return mysql_query($sqlStr);    }    /**     * 關(guān)閉MySQL連接     * @return bool     */    public function close()    {        return mysql_close($this->link);    }}
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
[php]自己寫的一個(gè)MySQL數(shù)據(jù)庫操作類
自己寫的MySQL數(shù)據(jù)庫操作類
Wordpress數(shù)據(jù)庫結(jié)構(gòu)全解析
PHPCMS后臺框架實(shí)現(xiàn)思路【原創(chuàng)】
PHP將數(shù)組存入數(shù)據(jù)庫中的四種方式
tp框架知識 之(鏈接數(shù)據(jù)庫和操作數(shù)據(jù))
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服