您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

mysql_query() 实施结果一直为false

2024/4/26 15:28:18发布6次查看
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 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)) {
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录