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
<!-- 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)) {

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

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

這篇文章帶大家解讀vue原始碼,來介紹一下Vue2中為什麼可以使用 this 存取各種選項中的屬性,希望對大家有幫助!

同事因為this指向的問題卡住的bug,vue2的this指向問題,使用了箭頭函數,導致拿不到對應的props。當我跟他介紹的時候他竟然不知道,隨後也刻意的看了一下前端交流群,至今最起碼還有70%以上的前端程式設計師搞不明白,今天給大家分享一下this指向,如果啥都沒學會,請給我一個大嘴巴子。

不,我們不能將頂級類別聲明為私有或受保護。它可以是公共或預設(無修飾符)。如果沒有修飾符,則應該具有預設存取權限。語法//Atoplevelclass publicclassTopLevelClassTest{ //Classbody}如果將一個頂級類別宣告為私有(private),編譯器將會報錯,提示「在此處不允許使用修飾符private」。這意味著頂級類別不能是私有的,同樣也適用於protected訪問

jQuery中this關鍵字的靈活運用在jQuery中,this關鍵字是一個非常重要且靈活的概念,它用來引用目前正在操作的DOM元素。透過合理的運用this關鍵字,我們可以方便地操作頁面中的元素,實現各種互動效果和功能。本文將結合具體的程式碼範例,介紹this關鍵字在jQuery中的靈活運用。簡單的this範例首先,我們來看一個簡單的this範例。假設我們有一
