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 ("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-> ; 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