Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL serve

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL serve

Post by lauthiamkok »

Hi,

This is very strange and doing my head in. I simply cannot understand why with the same content, the same scripts, and at the same server, it works on site but not the other, below is the error message,

http://nano-visions.net/dump/ - it works!
http://coexistencetrustnews.org/ - it doesn't!
Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL server host 'coexistencetrustnews.org.mysql' (2) in /customers/coexistencetrustnews.org/coexistencetrustnews.org/httpd.www/models/class_database.php on line 11 Connect failed: Unknown MySQL server host 'coexistencetrustnews.org.mysql' (2) Warning: mysqli::close(): Couldn't fetch mysqli in /customers/coexistencetrustnews.org/coexistencetrustnews.org/httpd.www/models/class_database.php on line 160
any idea?

below is my database class which I cannot find any error...

Code: Select all

<?php
#connects the database and handling the result
class __database {
	
	protected $connection = null;
	protected $error = null;

	#make a connection
	public function __construct($hostname,$username,$password,$database)
	{
		$this -> connection = new mysqli($hostname,$username,$password,$database);
		
		if (mysqli_connect_errno()) 
		{
			printf("Connect failed: %s\n", mysqli_connect_error());
			exit();
		}
	}
        
	#fetches all result rows as an associative array, a numeric array, or both
	public function fetch_all($query) 
	{
		$result = $this -> connection -> query($query);
		if($result) 
		{
			while($row = $result -> fetch_assoc())
			{
				$return_this[] = $row;
			}

			if (isset($return_this))
			{
				return $return_this;
			}
			else
			{
				return false;
			}
		}
		else
		{
			$this -> error = $this -> connection -> error;
			return false;
		}
	}
	
	#fetches a result row as an associative array, a numeric array, or both
	public function fetch_assoc_while($query)
	{
		$result = $this -> connection -> query($query);
		if($result) 
		{
			while($row = $result -> fetch_assoc())
			{
				$return_this[] = $row;
			}

			if (isset($return_this))
			{
				return $return_this;
			}
			else
			{
				return false;
			}
		}
		else
		{
			$this -> error = $this -> connection -> error;
			return false;
		}
	}
		
	#fetch a result row as an associative array
	public function fetch_assoc($query)
	{
		$result = $this -> connection -> query($query);
		if($result) 
		{
			return $result -> fetch_assoc();
		} 
		else
		{
			$this -> error = $this -> connection -> error;
			return false;
		}
	}
		
	#get a result row as an enumerated array
	public function fetch_row($query)
	{
		$result = $this -> connection -> query($query);
		if($result) 
		{
			return $result -> fetch_row();
		} 
		else
		{
			$this -> error = $this -> connection -> error;
			return false;
		}
	}
	
	#get the number of rows in a result
	public function num_rows($query)
	{
		$result = $this -> connection -> query($query);
		if($result) 
		{
			return $result -> num_rows;
		} 
		else
		{
			$this -> error = $this -> connection -> error;
			return false;
		}
	}
	
	#performs a query on the database
	public function query($query)
	{
		$result = $this -> connection -> query($query);	
		if($result) 
		{
			return $result;
		} 
		else
		{
			$this -> error = $this -> connection -> error;
			return false;
		}

	}
	
	#escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection
	public function real_escape_string($string)
	{
		$result = $this -> connection -> real_escape_string($string);	
		if($result) 
		{
			return $result;
		} 
		else
		{
			$this -> error = $this -> connection -> error;
			return false;
		}

	}
         
	#display error
	public function get_error() 
	{
		return $this -> error;
	}
	
	#closes the database connection when object is destroyed.
    public function __destruct()
    {
        $this -> connection -> close();
    }
}
?>
many thanks,
Lau
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL s

Post by John Cartwright »

Most certainly has nothing to do with the posted code, however, your error message tells you what the problem is. I can only assume coexistencetrustnews.org.mysql is not a valid hostname. Did you mean coexistencetrustnews.org? Furthermore, unless your database is not on the same server/network, then I would suggest changing it to localhost.
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Re: Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL s

Post by lauthiamkok »

John Cartwright wrote:Most certainly has nothing to do with the posted code, however, your error message tells you what the problem is. I can only assume coexistencetrustnews.org.mysql is not a valid hostname. Did you mean coexistencetrustnews.org? Furthermore, unless your database is not on the same server/network, then I would suggest changing it to localhost.
thanks for the reply. I tried to change it to localhost before but then it came out with another error message...

i dont undertand why it says that coexistencetrustnews.org.mysql is not a valid hostname - it is the hostname provided by the hosting server.

coexistencetrustnews.org is the url/ domain name of the site...
:banghead:
Post Reply