05-07-2008, 02:48 PM
|
#5 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by delayedinsanity
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::SERVER, self::USER, self::PASS, self::DB);
if (mysqli_connect_errno())
throw new Exception ('Doh MySQLi Exception: '.mysqli_connect_error());
}
}
$test = new DI_Test;
var_dump($test);
|
|
|
|