开发者

What in this program

I have been complete my class that will connecting to mysql server. When I running it I got an error:

Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in C:\wamp\www.php on line 18

Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: This is usually a (trying to connect via tcp://test:3306) in C:\wamp\www.php on line 18

Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in C:\wamp\www.php on line 18 Error cannnot connect to mysql server

I check my sql server that it had high privileges and dont have a password.

my code:

<?php
class mysql
{
    var $user;
    var $password;
    var $database;
    var $host;

    function mysql($username, $开发者_如何学运维password, $database, $host)
    {
        $this->user = $username;
        $this->password = $password;
        $this->database = $database;
        $this->host = $host;
    }
    function connect()
    {
        $conn = mysql_connect($this->host, $this->user, $this->password, $this->database)
                or die("Error cannnot connect to mysql server");
        echo "Connected successfully to Mysql server";
        mysql_close($conn);
    }
}
$connect = new mysql('127.0.0.1','root','','test');
$connect->connect();
?>


try:

$connect = new mysql('root','','test','127.0.0.1');


I suggest you to defined each property:

var $user;
var $password;
var $database;
var $host;

like these:

private $user;
private $password;
private $database;
private $host;

And create setter and getter methods for each property, an example:

public setUser($user){ 
   $this->user = $user; 
}

public getUser(){
   return $this->user;
}

Now, I'm sure you are asking yourself: Why? Here there is the answer :-)

bye

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜