[英]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.