View Single Post
Old 05-07-2008, 02:48 PM   #5 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
The problem is the @ doesn't seem to be suppressing the error from calling a new mysqli object...
If the code is precisely as you posted, the @ should suppress any error. If you're still getting the error message then show us a full copy/paste script which doesn't work for you so that we can try it.

The following file outputs (for me) the expected output (error successfully suppressed):
Doh MySQLi Exception: Access denied for user 'root'@'localhost' (using password: YES)
PHP Code:
<?php header('Content-Type: text/plain;charset=utf-8'); error_reporting(E_ALL E_STRICT);

class 
DI_Test {

    const 
SERVER 'localhost',
          
USER   'root',
          
PASS   'invalid',
          
DB     'talkphp_test';
    private 
$mysqli;

    public function 
__construct()
    {
        try {
            
$this->connectDB();
        } catch (
Exception $e) {
            die(
$e->getMessage());
        }
    }
    
    private function 
connectDB ()
    {
        
$this->mysqli = @new mysqli(self::SERVERself::USERself::PASSself::DB);
        if (
mysqli_connect_errno())
            throw new 
Exception ('Doh MySQLi Exception: '.mysqli_connect_error());
    }
}

$test = new DI_Test;
var_dump($test);
Salathe is offline  
Reply With Quote