請問MYSQLI無法讀取資料庫問題

來源:互聯網
上載者:User
 host = $host;      if ($user != "") $this -> user = $user;      if ($pass != "") $this -> pass = $pass;      if ($database != "") $this -> database = $database;       if (!$this -> conn = @mysqli_connect($this -> host, $this -> user, $this -> pass))  {        return $this -> output("串連資料庫 '".$this -> host."' 失敗。".mysqli_error($this -> conn));      }   mysqli_query($this -> conn,"SET NAMES 'utf8'");       $this -> selectdb();    }function selectdb($database=""){      if ($database != "" && $database != $this -> database)        $this -> database = $database;      if (!mysqli_select_db($this -> conn, $this -> database))  {        return $this -> output("無法使用資料庫 '".$this -> database."'。");      }}function query($sql="", $database="")                     //$sql{      if ($sql != "") $this -> sql = $sql;      if ($database != "" && $database != $this -> database)  {        $olddb = $this -> database;        $this -> selectdb($database);      }      $this -> result = @mysqli_query($this -> conn,$this -> sql);      if (mysqli_error($this -> conn) != "")  {        return $this -> output("執行以下SQL語句時失敗:'".$this -> sql."' 

".mysqli_error($this -> conn)); } $this -> n = @mysqli_affected_rows(); if (!empty($olddb)) $this -> selectdb($olddb); return $this -> result;}function get_data(){ if(!$this -> result || !preg_match("/^Resource/i", $this -> result)){ return $this->output("沒有資料,請先執行SQL的'select'語句!"); } $count=0; $this -> m = @mysqli_num_rows($this -> result); if ($this -> m > 0) { while ($row = mysqli_fetch_array($this -> result)){ $data[$count] = $row; $count++; } return $this->result=$data; } else { return $this -> output("資料為空白!"); } mysqli_free_result($this -> result);}function output($msg){ $this->err=$msg; if ($this->debug)echo $msg; return false;} }?>/////////////////////////////下面讀取資料////////////////////////////////////////////////////////////////////////////////////////////////////////////'0 ORDER BY de_id ASC"; $db -> query($sql); $result = $db -> get_data(); //這裡的$result沒有取值成功echo $result[0]["hp_id"];?>因php升級到5.6,把mysql的讀取方式全改mysqli了。結果資料輸出不了,要怎麼改才有資料輸出,本人小白,跪求大神指點。





回複討論(解決方案)

//你的$db 變數都沒有初始化對象$db = new mysqldb();

回複#1 的,不好意思 原文$db = new mysqldb(); 有的 我漏發上去了

print_r($db);
看看有什麼

回複 #3 的 原來 $sql = "SELECT * FROM t6_dept where de_id>'0 ORDER BY de_id ASC"; de_id>'0‘ 寫錯了 改後了瀏覽器報錯
PHP Warning: preg_match() expects parameter 2 to be string, object given in C:\inetpub\wwwroot\hp\4.php on line 80

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.