mysql_query() 實施結果一直為false

來源:互聯網
上載者:User
mysql_query() 執行結果一直為false
1)現有一個資料庫名為test,裡面只有一個表student。
屬性名稱:ID, Name, Email.
2)嘗試著將資料庫連接與操作封裝成一個類DatabaseManager,並擴充了一個類StudentDetailsDataManager來擷取學生資訊。
3)問題:能夠串連到test資料庫,sql語句在資料庫中測試過沒有問題,但mysql_query()執行sql語句結果一直為false。不知什麼問題?

代碼如下:
資料庫操作基類:DatabaseManager
PHP code
//DatabaseManager.phpconnection = $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!';        }    }?>


------
衍生類別:StudentDetailsDataManager
PHP code
//StudentDetailsDataManager.phphost = "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);        }    }?>


----
使用StudentDetailsDataManager執行個體擷取學生資訊
PHP code
getStudentInfo($ID, $data);    $stuDataManager->db_close();    echo $data["ID"];?>


------解決方案--------------------
mysql_error看一下就知道了
------解決方案--------------------
public function __construct($connection,$close_flag){
$this->connection = $connection;
$this->connection = $close_flag;
}
這麼嚴重的錯誤都看不出來?

另外
if (!mysql_select_db($this->name,$this->connection)) {
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.