mysql_query()实施结果一直为false
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql_query()实施结果一直为false,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1980字,纯文字阅读大概需要3分钟。
内容图文
![mysql_query()实施结果一直为false](/upload/InfoBanner/zyjiaocheng/217/9390e1518cbe4ca4b30b8e27fcfeac48.jpg)
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 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)) {
内容总结
以上是互联网集市为您收集整理的mysql_query()实施结果一直为false全部内容,希望文章能够帮你解决mysql_query()实施结果一直为false所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】