mysql-query()expects_mysql_query()实施结果一直为false

mysql_query() 执行结果一直为false

1)现有一个数据库名为test,里面只有一个表student。

属性名称:ID, Name, Email.

2)尝试着将数据库连接与操作封装成一个类DatabaseManager,并扩展了一个类StudentDetailsDataManager来获取学生信息。

3)问题:能够连接到test数据库,sql语句在数据库中测试过没有问题,但mysql_query()执行sql语句结果一直为false。不知什么问题?

代码如下:

数据库操作基类: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)) {

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值