每当我在我的网站上注册时,我都会收到这些错误,它不会将表保存在cms_users下,因此我无法登录。
[14-Aug-2014 19:58:53 UTC] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to MySQL server on 'SERVER IP' (4) in /home/blabbers/public_html/includes/classes.php on line 378
[14-Aug-2014 19:58:53 UTC] PHP Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/blabbers/public_html/includes/classes.php on line 379
[14-Aug-2014 19:58:53 UTC] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/blabbers/public_html/includes/classes.php on line 396
[14-Aug-2014 19:58:53 UTC] PHP Warning: mysql_result() expects parameter 1 to be resource, null given in /home/blabbers/public_html/includes/classes.php on line 420
[14-Aug-2014 19:58:53 UTC] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/blabbers/public_html/includes/classes.php on line 396
[14-Aug-2014 19:58:53 UTC] PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in /home/blabbers/public_html/includes/classes.php on line 400
[14-Aug-2014 19:58:53 UTC] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/blabbers/public_html/includes/classes.php on line 396
[14-Aug-2014 19:58:53 UTC] PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in /home/blabbers/public_html/includes/classes.php on line 400
[编辑]这是文件。马里奥告诉我这还不够,希望能有效。
class HoloDatabase {
var $connection;
var $error;
var $lastquery;
function HoloDatabase($conn){
switch($conn['server']){
case "mysql":
$this->connection = mysql_connect($conn['host'].":".$conn['port'], $conn['username'], $conn['password'], true);
mysql_select_db($conn['database'],$this->connection) or $this->error = mysql_error();
break;
case "pgsql":
$this->connection = pg_connect("host=".$conn['host']." port=".$conn['port']." dbname=".$conn['database']." user=".$conn['username']." password=".$conn['password']);
break;
case "sqlite":
$this->connection = sqlite_open($conn['host'], 0666, $this->error);
break;
case "mssql":
$this->connection = mssql_connect($conn['host'].",".$conn['port'],$conn['username'],$conn['password'],true);
break;
}
}
}
class mysql extends HoloDatabase {
function query($query){
if(defined('DEBUG')){ $this->lastquery = $query; }
$query = mysql_query($query,$this->connection);
return $query;
}
function fetch_assoc($query){
$result = mysql_fetch_assoc($query);
if(defined('DEBUG')){ $error = mysql_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function fetch_row($query){
$result = mysql_fetch_row($query);
if(defined('DEBUG')){ $error = mysql_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function fetch_array($result,$result_type=0){
$result = mysql_fetch_array($result,$result_type);
if(defined('DEBUG')){ $error = mysql_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function num_rows($query){
$result = mysql_num_rows($query);
if(defined('DEBUG')){ $error = mysql_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function result($query,$row=0,$column=0){
$result = mysql_result($query,$row,$column);
if(defined('DEBUG')){ if($result == false){ echo mysql_error($this->connection) . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function insert_id($query=null){
return mysql_insert_id($this->connection);
}
}
class pgsql extends HoloDatabase {
function query($query){
if(defined('DEBUG')){ $this->lastquery = $query; }
$query = pg_query($this->connection,$query);
return $query;
}
function fetch_assoc($query){
$result = pg_fetch_assoc($query);
if(defined('DEBUG')){ $error = pg_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function fetch_row($query){
$result = pg_fetch_row($query);
if(defined('DEBUG')){ $error = pg_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function fetch_array($result,$result_type=0){
$result = pg_fetch_array($result,null,$result_type);
if(defined('DEBUG')){ $error = pg_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function num_rows($query){
$result = pg_num_rows($query);
if(defined('DEBUG')){ $error = pg_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function result($query,$row=0,$column=0){
$result = pg_fetch_result($query,$row,$column);
if(defined('DEBUG')){ if($result == false){ echo pg_last_error($this->connection) . "<br />Query that errored: ".$this->lastquery; } }
return $result;
}
function insert_id($query){
return pg_last_oid($query);
}
}
我该如何解决这个问题?
谢谢, 马修
答案 0 :(得分:1)
MySQL驱动程序期待connection resource
;但是当连接失败时,它返回false
。
因此错误&#34;期望资源,布尔给出&#34;
在这种情况下,您没有获得连接,因为没有正确配置mysql的参数。
您应该在某个地方$db = new HoloDatabase($someConfiguration)
- 查看$someConfiguration
并确保您已设置服务器IP /用户名&amp;密码正确。
代替这一点,确保MySQL通过telnet xx.xx.xx.xx 3306
接受连接。如果它是远程服务器,请确保已设置mysql以进行远程连接。
Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user