国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

操作MYSQL的一個PHP類

2024-07-24 12:56:17
字體:
來源:轉載
供稿:網友
  • 網站運營seo文章大全
  • 提供全面的站長運營經驗及seo技術!
  •  

    <?php
    /*
    *
    這個類本來是phplib里的一部分,我做了些修改。
    */
    class mydb_sql {
    var $host = "";
    var $database = "";
    var $user = "";
    var $password = "";

    var $link_id = 0;
    var $query_id = 0;
    var $record = array();
    var $row;

    var $errno = 0;
    var $error = "";

    var $auto_free = 0; ## set this to 1 for automatic mysql_free_result()
    var $auto_commit = 0; ## set this to 1 to automatically commit results

    var $debugmode = 0;

    function connect() {
    if ( 0 == $this->link_id ) {
    $this->link_id=mysql_pconnect($this->host, $this->user, $this->password);
    if (!$this->link_id) {
    $this->halt("link-id == false, pconnect failed");
    }
    if (!mysql_query(sprintf("use %s",$this->database),$this->link_id)) {
    $this->halt("cannot use database ".$this->database);
    }
    }
    }

    function query($query_string) {
    $this->connect();

    if ($this->debugmode)
    printf("debug: query = %s<br>/n", $query_string);

    $this->query_id = mysql_query($query_string,$this->link_id);
    $this->row = 0;
    $this->errno = mysql_errno();
    $this->error = mysql_error();
    if (!$this->query_id) {
    $this->halt("invalid sql: ".$query_string);
    }

    return $this->query_id;
    }

    function next_record() {
    $this->record = mysql_fetch_array($this->query_id);
    $this->row += 1;
    $this->errno = mysql_errno();
    $this->error = mysql_error();

    $stat = is_array($this->record);
    if (!$stat && $this->auto_free) {
    mysql_free_result($this->query_id);
    $this->query_id = 0;
    }
    return $stat;
    }

    function seek($pos) {
    $status = mysql_data_seek($this->query_id, $pos);
    if ($status)
    $this->row = $pos;
    return;
    }

    function metadata($table) {
    $count = 0;
    $id = 0;
    $res = array();

    $this->connect();
    $id = @mysql_list_fields($this->database, $table);
    if ($id < 0) {
    $this->errno = mysql_errno();
    $this->error = mysql_error();
    $this->halt("metadata query failed.");
    }
    $count = mysql_num_fields($id);

    for ($i=0; $i<$count; $i++) {
    $res[$i]["table"] = mysql_field_table ($id, $i);
    $res[$i]["name"] = mysql_field_name ($id, $i);
    $res[$i]["type"] = mysql_field_type ($id, $i);
    $res[$i]["len"] = mysql_field_len ($id, $i);
    $res[$i]["flags"] = mysql_field_flags ($id, $i);
    $res["meta"][$res[$i]["name"]] = $i;
    $res["num_fields"]= $count;
    }

    mysql_free_result($id);
    return $res;
    }

    function affected_rows() {
    return mysql_affected_rows($this->link_id);
    }

    function num_rows() {
    return mysql_num_rows($this->query_id);
    }

    function num_fields() {
    return mysql_num_fields($this->query_id);
    }

    function nf() {
    return $this->num_rows();
    }

    function np() {
    print $this->num_rows();
    }

    function f($name) {
    return $this->record[$name];
    }

    function p($name) {
    print $this->record[$name];
    }

    function halt($msg) {
    printf("</td></tr></table><b>database error:</b> %s<br>/n", $msg);
    printf("<b>mysql error</b>: %s (%s)<br>/n",
    $this->errno,
    $this->error);
    die("session halted.");
    }
    }

    class sql extends mydb_sql {
    var $host = "localhost";
    var $database = "";
    var $user = "";
    var $password = "";

    function free_result() {
    return @mysql_free_result($this->query_id);
    }

    function rollback() {
    return 1;
    }

    function commit() {
    return 1;
    }

    function autocommit($onezero) {
    return 1;
    }

    function insert_id($col="",$tbl="",$qual="") {
    return mysql_insert_id($this->query_id);
    }
    }
    ?>

     

    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 江陵县| 仁布县| 扬中市| 息烽县| 确山县| 伊宁县| 靖边县| 廉江市| 玉山县| 乐东| 运城市| 太康县| 冷水江市| 纳雍县| 隆德县| 克山县| 临漳县| 大埔区| 华阴市| 北碚区| 莲花县| 隆子县| 内乡县| 岢岚县| 茂名市| 亚东县| 沙田区| 洪泽县| 桐梓县| 三台县| 武清区| 太仆寺旗| 绩溪县| 鄂伦春自治旗| 蕲春县| 哈巴河县| 乌拉特前旗| 五指山市| 富顺县| 广宗县| 吕梁市|