Application mysqli reading the database can't read the problem

Source: Internet
Author: 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-&gt ; Output ("Connect database". $this, host. "' Failed.      ". Mysqli_error ($this-conn));       } mysqli_query ($this, Conn, "SET NAMES ' UTF8 '");    $this-Selectdb (); }function selectdb ($database = "") {if ($database! = "" && $database! = $this database) $this-&gt ;      Database = $database;  if (!mysqli_select_db ($this, Conn, $this) {return $this, output ("Cannot use database". $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 ("failed when executing the following SQL statement: '". $this-SQL. "'

". Mysqli_error ($this-conn)); } $this n = @mysqli_affected_rows ($this-conn); if (!empty ($OLDDB)) $this, Selectdb ($OLDDB); return $this, result;} function Get_data () {/* if (! $this, Result | |!preg_match ("/^resource/i", $this, result)) {*/ if (! $this, Result | |!is_resource ($this->result)) {return $this->output ("No data, first execute SQL ' SELECT ' statement !"); } $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 ("Data is empty!"); } mysqli_free_result ($this, result);} function output ($msg) {$this->err= $msg; if ($this->debug) echo $msg; return false;} }?> /////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////// "; Echo"
";} $sql = "SELECT * from t6_dept where de_id> ' 0 ' ORDER by de_id ASC"; $db, query ($sql); $result = $db-Get_data (); if (! $result) {echo "Failed to remove data" result 0 "; echo"
"; Echo"
";} echo $result [0]["De_name"]; Unable to display data print_r ($DB);? >


Finally output data $resul no value t browser display results: What error???

Link Database 1

Failed to remove data result 0

MySQLdb Object ([host] + localhost [user] = root [pass] = 1234 [Database] = T6_DB_HP [conn] = Mysqli Object ([affected_rows] = 4 [Client_info] = Mysqlnd 5.0.11-dev-20120503-$Id: f373ea5dd5538761406a8022a4b8a37 4418B240E $ [Client_version] = 50011 [Connect_errno] = 0 [Connect_error] = [errno] + 0 [ERROR] = [Erro R_list] + Array () [Field_count] = 4 [host_info] + localhost via TCP/IP [INFO] = [insert_id] + 0 [ser Ver_info] = 5.6.20 [Server_version] = 50620 [stat] = uptime:22428 threads:1 questions:5 Slow queries:0 Ope ns:68 Flush tables:1 Open tables:61 Queries per second avg:0.000 [sqlstate] = 00000 [Protocol_version] = [t HREAD_ID] + 1 [warning_count] = 0) [SQL] = SELECT * from t6_dept where de_id> ' 0 ' ORDER by de_id ASC [n] =& Gt 4 [M] = 0 [result] = Mysqli_result Object ([Current_field] = 0 [Field_count] + 4 [lengths] = = [Num_row S] = 4 [Type] =&Gt 0) [Debug] + [ERR] = no data, please execute SQL ' SELECT ' statement first! )


Reply to discussion (solution)

Mysqli_query ($this-Conn, $this-SQL) returns a Mysqli_result object, not a resource (resource)
So!is_resource ($this->result) was set up and the program ended prematurely.

Mysqli_query ($this-Conn, $this-SQL) returns a Mysqli_result object, not a resource (resource)
So!is_resource ($this->result) was set up and the program ended prematurely.



How to change???

if (! $this, Result | |!is_object ($this->result)) {
return $this->output ("No data, please execute SQL ' SELECT ' statement first!");
}

if (! $this, Result | |!is_object ($this->result)) {
return $this->output ("No data, please execute SQL ' SELECT ' statement first!");
}



Finally solved the problem for many days, thank you moderator
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.