Can't figure out warning message

Hi there,
I have this warning message output each time I run this script. I dont seem to be able to figure it out.

Here’s my script:


<?php


class database {
    
    /* --- properties/variables. --- */
    private $host = 'localhost';
    private $usrnm =  'root';
    private $pass = 'wawa';
    private $model = 'ize';
    
    public $error = 'A general system mulfunction occurred. Please try again later ';
    public $sql;
    
    /* --- methods -- */
    
    // THE CONSTRUCTOR METHOD.
    public function __construct($query){
        $this->sql = $query;
        
    }
    
    // DATABASE CONNECTION.
    public function connect(){
        $db = mysql_connect($this->host,$this->usrnm,$this->pass);
        
        //test connection
        if (!$db){
            die($this->error);    
        } 
        
        return $db;
    }
    
    // SELECT DATABASE TABLE.
    public function select(){
        
        $select = mysql_select_db($this->model, $this->connect());
        
        //test selection.
        if(!$select) {
            die($this->error);
        }
    }
    
    
    // DISPLAY TABLE FUNCTION.
    public function display($sql){
        $result = mysql_query($sql,$this->connect());
        
        if (!$result){
            die('Unable to retrieve data ' . mysql_error());
        } else {
            echo '<br/>';    
            
            //open table...
            echo '<table align="left" cellspacing="3"
            cellpadding="3" width="70%">
            <tr><td align="left"><b>Username</b></td>
            <td align="left"><b>Email</b></td>
            <td align="left"><b>Password</b></td></tr>
            
            ';

            while ($row = mysql_fetch_array($result)) {
                echo '<tr><td align="left">' . $row['firstname'] . '</td>
                <td align="left">' . $row['lastname'] . '</td>
                <td align="left">' . $row['email'] . '</td>
                </tr>';
            }
                echo '</table>'; //close table
        }
    }

    
    
}
$sql = 'SELECT * FROM user';

$obj = new database($sql);
$obj->connect();

$obj->select();
$obj->display($sql);


?>

and PHP is throwing this error/warning:


Warning: mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/itenzo/Sites/myprojects/includes/database.php on line 27

Line 27 is where my connect function is $db = mysql_connect();

Thanks

Do you have MySQL installed? If so, try substituting ‘localhost’ with ‘127.0.0.1’.

If you use ‘localhost’ on a *nix server, it tries to connect using a socket, which you don’t have set up. However, if you use use an IP address it connects via TCP/IP, so we cheat by using 127.0.0.1. :wink:

Off Topic:

It appears that MySQL qualification is useful after all! :smiley:

If you restart the MySQL service, the socket should be recreated. Although, I cannot offer any insight as to why it disappeared in the first place! :slight_smile:

…that sounds like some ‘nerdy stuff’ right there!

So does it mean its now changed I should always use the IP address in my scripts or that was just temporary after a while I can go back to using ‘localhost’?

I’m still oblivious as to why this happened, whats the cause?

Yes it worked… So what was the problem?

Yes I have MySQL installed been working with MySQL past few days… what was the problem then, where did i go wrong or what might have happened?

Thanks again.