The implementation result of mysql_query () is always false.

Source: Internet
Author: User
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 )){

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.