mysql query false_mysql_query() 实施结果一直为false
mysql_query() 執(zhí)行結(jié)果一直為false
1)現(xiàn)有一個數(shù)據(jù)庫名為test,里面只有一個表student。
屬性名稱:ID, Name, Email.
2)嘗試著將數(shù)據(jù)庫連接與操作封裝成一個類DatabaseManager,并擴展了一個類StudentDetailsDataManager來獲取學生信息。
3)問題:能夠連接到test數(shù)據(jù)庫,sql語句在數(shù)據(jù)庫中測試過沒有問題,但mysql_query()執(zhí)行sql語句結(jié)果一直為false。不知什么問題?
代碼如下:
數(shù)據(jù)庫操作基類: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!';
}
}
?>
------
派生類: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);
}
}
?>
----
使用StudentDetailsDataManager實例獲取學生信息
PHP codegetStudentInfo($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)) {
相關文章
相關視頻
總結(jié)
以上是生活随笔為你收集整理的mysql query false_mysql_query() 实施结果一直为false的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python最优分箱计算iv值_GitH
- 下一篇: lightroom手机版下载_vnc控制