簡體   English   中英

為什么我的mysqli_connect沒有連接? 它說沒有指定主機名

[英]Why isn't my mysqli_connect connecting? It says no hostname was specified when one is

我正在為我的投資組合編寫一個簡單的博客網絡應用程序,我遇到了這個奇怪的問題。 我編寫了一個PHP腳本來連接數據庫,並通過RESTful調用將數據讀寫到數據庫。

我之前在其他程序中沒有遇到任何問題,但是在這一次我得到了一個錯誤。 我寫了一個簡單的測試頁面來檢查RESTful調用在我開始在我的主應用程序中使用之前是否有效。 我沒有工作,而是從PHP腳本中收到錯誤。

錯誤是這樣的:

警告:mysqli_connect()[function.mysqli-connect] :( HY000 / 2002):無法通過套接字連接到本地MySQL服務器'/ No-MySQL-hostname-was-specified'(2)in home / releesquirrel /第35行的storage.electricsquirrel.net/SimpleBlog/php/model_SimpleBlog.php

導致第35行的代碼如下:

class model_SimpleBlog {
// Properties

// Database Info
private $serverName = "mysql.electricsquirrel.net";
private $userName = "esqrl_client";
private $userPassword = "fakepassword";
private $dbaseName = "esquirrel_simpleblog";


// Methods
public function model_SimpleBlog() {
    //
}

// Load the ten latest entries after an offset
public function loadEntries($offset) {

    $result = false;

    // Connect to the Database Server

    $connection = mysqli_connect($serverName, $userName, $userPassword, $dbaseName);

我已經更改了隱私密碼,但這是拋出錯誤的代碼。 我完全難過了。 我以前使用的代碼與此類似,沒有任何問題,我嘗試使用谷歌搜索錯誤代碼沒有運氣。

有誰知道我為什么會收到此錯誤以及我可以做些什么來修復我的代碼?

在PHP中,您需要使用$this->引用對象變量:

$connection = mysqli_connect($this->serverName, $this->userName, $this->userPassword, $this->dbaseName);

例如, $serverName在函數范圍內查找具有該名稱的變量。 顯然沒有。

有關PHP對象屬性的更多信息,請參見手冊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM