<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## mysqli數據庫操作類封裝 > 慕課網老師常用的類庫 ~~~ <?php /** * 操作數據庫mysql 的類,完成增刪改查的操作 * */ class ms_new_mysql { private $dbHost; private $dbUser; private $dbPassword; private $dbTable; private $dbConn; private $result; private $sql; private $pre; private $coding; private $pcon; private $queryNum; private static $daoImpl; public function __construct($dbHost, $dbUser, $dbPassword, $dbTable, $pre, $coding, $pcon) { $this->dbHost = $dbHost; $this->dbUser = $dbUser; $this->dbPassword = $dbPassword; $this->dbTable = $dbTable; $this->pre = $pre; $this->coding = $coding; $this->pcon = $pcon; $this->connect(); $this->select_db($dbTable); } public function __clone() { return self::$daoImpl; } public static function getDaoImpl($linkConfig) { if (empty(self::$daoImpl)) { self::$daoImpl = new ms_new_mysql($linkConfig['db']['dbhost'], $linkConfig['db']['dbuser'], $linkConfig['db']['dbpw'], $linkConfig['db']['dbname'], $linkConfig['db']['tablepre'], $linkConfig['db']['dbcharset'], $linkConfig['db']['pconnect']); } return self::$daoImpl; } public function connect() { $func = $this->pcon == 1 ? "mysql_pconnect" : "mysql_connect"; //$this->dbConn = @$func($this->dbHost, $this->dbUser, $this->dbPassword); $this->dbConn = mysql_connect($this->dbHost, $this->dbUser, $this->dbPassword, $this->pcon); if (!$this->dbConn) { $this->halt("不能鏈接數據庫", $this->sql); return false; } if ($this->version() > '4.1') { $serverset = $this->coding ? "character_set_connection='$this->coding',character_set_results='$this->coding',character_set_client=binary" : ''; $serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',') . " sql_mode='' ") : ''; $serverset && mysql_query("SET $serverset", $this->dbConn); } return $this->dbConn; } /** * 選擇一個數據庫 * * @param string $dbTable * @return boolean */ public function select_db($dbTable) { if (!@mysql_select_db($dbTable, $this->dbConn)) { $this->halt("沒有" . $dbTable . "這個數據庫"); return false; } else { $this->dbTable = $dbTable; return true; } } /** * 查詢語句,傳過來一個sql,執行,如果語句正確,返回結果集資源 * * @param string $sql * @param string $type * @return Resouce query */ public function query($sql, $type = '') { if ($query = mysql_query($sql, $this->dbConn)) { $this->queryNum++; return $query; } else { $this->halt("Mysql 查詢出錯", $sql); return false; } } /** * 插入一組數據或一條數據 * * @param string $tableName * @param boolean */ public function insert($tableName, $info) { $this->checkFields($tableName, $info); $insert_sql = "INSERT INTO `$tableName`(`" . implode('`,`', array_keys($info)) . "`) VALUES('" . implode("','", $info) . "')"; return $this->query("$insert_sql"); } /** * 更細數據庫中的數據 * * @param string $tableName * @param array $info * @param string $where * @return boolean */ public function update($tableName, $info, $where = '') { $this->checkFields($tableName, $info); if ($where) { $sql = ''; foreach ($info as $k => $v) { $sql .= ", `$k`='$v'"; } $sql = substr($sql, 1); $sql = "UPDATE `$tableName` SET $sql WHERE $where"; } else { $sql = "REPLACE INTO `$tableName`(`" . implode('`,`', array_keys($info)) . "`) VALUES('" . implode("','", $info) . "')"; } return $this->query($sql); } /** * 檢查一個字段是否在這張表中存在 * * @param string $tableName * @param array $array * @return message */ public function checkFields($tableName, $array) { $fields = $this->getFields($tableName); foreach ($array as $key => $val) { if (!in_array($key, $fields)) { $this->halt("Mysql 錯誤", "找不到" . $key . "這個字段在" . $tableName . "里面"); return false; } } } /** * 獲取一張表中的所有字段 * * @param string $tableName * @return array fileds */ public function getFields($tableName) { $fields = array(); $result = $this->query("SHOW COLUMNS FROM `$tableName`"); while ($list = $this->fetchArray($result)) { $fields[] = $list['Field']; } $this->freeResult($result); return $fields; } /** * 釋放當前數據庫結果集的內存 * * @param Resource $result * @return null */ public function freeResult($result) { return @mysql_free_result($result); } /** * 使用while 可以迭代輸出 一個結果集中的所有數據 * * @param Resouce $query * @param result type $result_type * @return array */ public function fetchArray($query, $result_type = MYSQL_ASSOC) { return mysql_fetch_array($query, $result_type); } /** * 返回一個結果集中的一條數據 * * @param $sql $query * @param string $type * * */ public function getOne($sql, $type = '', $expires = 3600) { $query = $this->query($sql, $type, $expires); $rs = $this->fetchArray($query); $this->freeResult($rs); return $rs; } /** * 獲取插入的數據的返回的insetid * * @return insetid */ public function insertId() { return mysql_insert_id($this->dbConn); } /** * 獲取當前的結果集中存在多少條數據 * * @param string $query * @return int nums */ public function numRows($query) { return @mysql_numrows($query); } /** * 獲取當前的結果集中,有多少個字段 * * @param Resouce $query * @return int fields nums */ public function numFields($query) { return @mysql_num_fields($query); } /** * 獲取當前執行的sql總條數 * * @return queryNum */ public function getQueryNum() { return $this->queryNum; } /** * 獲取當前文件中的函數,傳入一個當前類存在函數,單例調用 * * @param unknown_type $funcname * @param unknown_type $params * @return unknown */ public function getFunc($funcname, $params = '') { if (empty($params)) { return $this->$funcname(); } else { return $this->$funcname($this->getFuncParams($params)); } } /** * 如果是一個數組,那么拼接起來,處理返回一個參數集合 * * @param array,string $params * @return string a,d,3 */ public function getFuncParams($params) { $returnStr = ""; if (is_array($params)) { foreach ($params as $key => $val) { $returnStr .= $val . ","; } return rtrim($returnStr, ","); } else { return $params; } } /** * 獲取當前數據庫的版本信息 * * @return version */ public function version() { return mysql_get_server_info($this->dbConn); } /** * 獲取當前mysql數據的報錯號 * * @return errorno */ public function errno() { return intval(@mysql_errno($this->dbConn)); } /** * 獲取當前數據庫的 提示信息 * * @return unknown */ public function error() { return @mysql_error($this->dbConn); } /** * 操作數據庫出錯,提示信息 * * @param unknown_type $message * @param unknown_type $sql */ function halt($message = '', $sql = '') { $this->errormsg = "<b>MySQL Query : </b>$sql <br /><b> MySQL Error : </b>" . $this->error() . " <br /> <b>MySQL Errno : </b>" . $this->errno() . " <br /><b> Message : </b> $message"; exit($this->errormsg); } function showTable() { $tables = array(); $result = $this->query("SHOW TABLES"); while ($list = $this->fetchArray($result)) { $tables[] = $list['Tables_in_' . $this->dbTable]; } $this->freeResult($result); return $tables; } } $dbObj = new ms_new_mysql("127.0.0.1", "root", "", "mukewang", "", "utf-8", "0"); ?> ~~~
                  <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>

                              哎呀哎呀视频在线观看