0

I am getting these errors whenever I sign up on my website, It doesn't save the table under cms_users so I can't login.

[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

[EDIT] Here is the file. Mario told me it wasn't enough, Hopefully this work.

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);
    }
}

How do I fix this?

Thanks, Matthew

  • 1
    `on 'SERVER IP'` is a giveaway for a misconfiguration. Your question does not contain enough information to diagnose anything. The instantion of your connection wrapper would be relevant. Also don't append `[OPEN]` to titles. – mario Aug 14 '14 at 22:25
  • What should I do want me to give you the whole file. – MatthewTheMan2 Aug 14 '14 at 22:28
  • You may want to look into using `mysqli` instead of `mysql` as the latter is deprecated. – Lochemage Aug 14 '14 at 22:33
  • Your connection is failing, and based on your warnings it looks like you are doing something like -> `$a=new HoloDatabase; $a->HoloDatabase(array('host'=>'SERVER IP',...` where `SERVER IP` is not a valid host. – Sean Aug 14 '14 at 22:37
  • I took out the Server IP, So I don't give anybody the IP. "Server IP" is where my actual ip going to be – MatthewTheMan2 Aug 14 '14 at 22:39
  • How is it not valid, I port forward everything. wtf – MatthewTheMan2 Aug 14 '14 at 22:39

1 Answers1

1

The MySQL driver is expecting a connection resource; however when the connection fails it returns false.

Hence the error "expected resource, boolean given"

In this case, you're not getting a connection, because a parameter for mysql hasn't been configured correctly.

You should have somewhere $db = new HoloDatabase($someConfiguration) - take a look at $someConfiguration and make sure you've set the server IP / username & password up correctly.

In lieu of that, make sure that MySQL is accepting connections via telnet xx.xx.xx.xx 3306. If it's a remote server, make sure that mysql is set up to take remote connections.

Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user

Community
  • 1
  • 1
nathan-m
  • 8,885
  • 2
  • 17
  • 29