mysql_query() 执行结果一直为false
1)现有一个数据库名为test,里面只有一个表student。
属性名称:ID, Name, Email.
2)尝试着将数据库连接与操作封装成一个类DatabaseManager,并扩展了一个类StudentDetailsDataManager来获取学生信息。
3)问题:能够连接到test数据库,sql语句在数据库中测试过没有问题,但mysql_query()执行sql语句结果一直为false。不知什么问题?
代码如下:
数据库操作基类:DatabaseManager
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> //DatabaseManager.php <?php class DatabaseManager{ protected $host; protected $name; protected $user; protected $psw; protected $connection; protected $close_flag; public function __construct($connection,$close_flag){ $this->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
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> //StudentDetailsDataManager.php <?php require 'DatabaseManager.php'; class StudentDetailsDataManager extends DatabaseManager{ public function __construct($connection="",$close_flag=true){ parent::__construct($connection, $close_flag); $this->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
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?php require_once 'StudentDetailsDataManager.php'; $stuDataManager = new StudentDetailsDataManager(); $ID = "DA123456"; $data=NULL; $stuDataManager->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)) {

CONNECTION_REFUSED是一种网络连接错误,通常会在试图连接到远程服务器时出现。当客户端设备试图建立一个与服务器的网络连接时,如果服务器拒绝该连接请求,就会返回一个CONNECTION_REFUSED错误。常见的原因包括:服务器未启动、服务器无法接受更多的连接请求、服务器防火墙阻止了该连接等。

解决方法:1、检查网络连接;2、检查服务器状态;3、清除缓存和Cookie;4、检查防火墙和安全软件设置;5、尝试使用其他网络等等。

如果你使用PHP连接MySQL数据库时遇到了以下错误提示:PHPWarning:mysqli_connect():(HY000/2002):Connectionrefused那么你可以尝试按照下面的步骤来解决这个问题。确认MySQL服务是否正常运行首先应该检查MySQL服务是否正常运行,如果服务未运行或者启动失败,就可能会导致连接被拒绝的错误。你可

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

不,我们不能将顶级类声明为私有或受保护。它可以是公共或默认(无修饰符)。如果没有修饰符,则应该具有默认访问权限。语法//Atoplevelclass publicclassTopLevelClassTest{ //Classbody}如果将一个顶级类声明为私有(private),编译器将会报错,提示“在此处不允许使用修饰符private”。这意味着顶级类不能是私有的,同样也适用于protected访问

同事因为this指向的问题卡住的bug,vue2的this指向问题,使用了箭头函数,导致拿不到对应的props。当我给他介绍的时候他竟然不知道,随后也刻意的看了一下前端交流群,至今最起码还有70%以上的前端程序员搞不明白,今天给大家分享一下this指向,如果啥都没学会,请给我一个大嘴巴子。

本篇文章带大家解读vue源码,来介绍一下Vue2中为什么可以使用 this 访问各种选项中的属性,希望对大家有所帮助!

一、this关键字1.this的类型:哪个对象调用就是哪个对象的引用类型二、用法总结1.this.data;//访问属性2.this.func();//访问方法3.this();//调用本类中其他构造方法三、解释用法1.this.data这种是在成员方法中使用让我们来看看不加this会出现什么样的状况classMyDate{publicintyear;publicintmonth;publicintday;publicvoidsetDate(intyear,intmonth,intday){ye


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor
