<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                平時寫代碼,都會涉及到數據庫操作,如果不用框架的話,數據庫的增、刪、改、查操作要多次重復,很麻煩,所以自己封裝寫一個類,只要在需要數據庫操作的頁面引入這個類,然后就可以方便的進行調用,可以省下很多代碼。 源碼如下: <?php header('Content-type:text/html;charset="utf-8"'); class Db{ /* 數據庫相關信息 */ static $db; static $host = 'localhost';//數據庫地址 static $dbname = 'photos';//數據庫名 static $username = 'photos';//數據庫用戶名 static $userpwd = 'photos';//數據庫密碼 /* 連接數據庫 */ static function run(){ self::$db = new PDO('mysql:host=localhost;dbname='.self::$dbname, self::$username, self::$userpwd); self::$db->query('set names utf8'); } /* 增 */ //$tableName是數據庫名,$arry是需要插入的數據,是一維關聯數組 static function add($tableName, $arry){ $sql = 'insert into '.$tableName.' set '; foreach($arry as $key=>$value){ $sql .= $key.'='."'$value',"; } $sql = rtrim($sql, ','); self::$db->query($sql); return self::$db->lastInsertId(); } //$tableName是數據庫名,$arry是需要插入的數據,是二維關聯數組 static function addAll($tableName, $arry){ $tmpArry = array(); foreach($arry as $key=>$value){ $sql = 'insert into '.$tableName.' set '; foreach($value as $k=>$v){ $sql .= $k.'='."'$v',"; } $sql = rtrim($sql, ','); if(self::$db->query($sql)){ array_push($tmpArry, self::$db->lastInsertId()); } } return $tmpArry; } /* 刪 */ // //$tableName是數據庫名,$arry是where條件,$status是狀態(or、and) static function delete($tableName, $arry, $status=0){ $sql = 'delete from '.$tableName. ' where '; if($status==1){ foreach($arry as $key=>$value){ $sql .= $key.'='."'$value' and "; } $sql = rtrim($sql, ' and '); return self::$db->query($sql); }else if($status==2){ foreach($arry as $key=>$value){ $sql .= $key.'='."'$value' or "; } $sql = rtrim($sql, ' or '); return self::$db->query($sql); }else{ foreach($arry as $key=>$value){ $sql .= $key.'='."'$value'"; } } return self::$db->query($sql); } /* 改 */ // //$tableName是數據庫名,$arry是需要更新的數據,$condition是where條件 static function update($tableName, $arry, $condition){ $sql = 'update '.$tableName. ' set '; foreach($arry as $key=>$value){ $sql .= $key.'='."'$value',"; } $sql = rtrim($sql, ','); foreach($condition as $key=>$value){ $sql .= ' where '.$key.'='."'$value'"; } return self::$db->query($sql); } /* 查 */ // //$tableName是數據庫名,$arry是查詢的字段 static function select($tableName, $arry=array('*')){ $sql = 'select '; foreach($arry as $key=>$value){ $sql .= $value.','; } $sql = rtrim($sql, ','); $sql .= ' from '.$tableName; $obj = self::$db->query($sql); $result = $obj->fetchAll(PDO::FETCH_ASSOC); return $result; } } Db::run();
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看