The execution result of mysql_query () has always been false1. Currently, one database named test has only one table, student. Attribute Name: ID, Name, Email.2) tries to encapsulate database connections and operations into a DatabaseManager class, and extends the execution result of a class StudentDetail mysql_query () to false.
1) a database named test has only one student.
Attribute Name: ID, Name, Email.
2) try to encapsulate database connections and operations into a class DatabaseManager, and extend the class StudentDetailsDataManager to obtain student information.
3) problem: you can connect to the test Database. the SQL statement has been tested in the database, but the result of executing the SQL statement mysql_query () is always false. What's the problem?
The code is as follows:
Database operation base class: DatabaseManager
PHP code
//DatabaseManager.php
connection = $connection; $this->connection = $close_flag; } protected function db_open(){ if(empty($this->connection)){ $this->connection = mysql_connect($this->host,$this->user,$this->psw); if (!$this->connection) { $this->db_handle_error_connetion(); return false; } if (!mysql_select_db($this->name,$this->connection)) { $this->da_handle_select(); return false; } } } public function db_close(){ if($this->connection) mysql_close($this->connection); } protected function db_handle_error_connetion(){ echo 'Failed connetion'; } protected function db_handle_select(){ echo 'Failed access database!'; } }?>
------
Derived class: StudentDetailsDataManager
PHP code
//StudentDetailsDataManager.php
host = "localhost"; $this->user = "root"; $this->psw = "root"; $this->name = "test"; $this->db_open(); } public function getStudentInfo($ID,&$data){ //$query = "SELECT * FROM student WHERE ID ='$ID'"; $query = "select * from student where ID = '$ID'"; $result = mysql_query($query); //print_r($result); if (!$result) { echo "result is empty!!"; return false; } $data = mysql_fetch_array($result,MYSQL_ASSOC); mysql_free_result($result); } }?>
----
Use the StudentDetailsDataManager instance to obtain student information
PHP code
getStudentInfo($ID, $data); $stuDataManager->db_close(); echo $data["ID"];?>
------ Solution --------------------
Mysql_error: Check it out.
------ Solution --------------------
Public function _ construct ($ connection, $ close_flag ){
$ This-> connection = $ connection;
$ This-> connection = $ close_flag;
}
Can't you see such a serious error?
In addition
If (! Mysql_select_db ($ this-> name, $ this-> connection )){