Reputation: 32
Is there a way I can either validate the connection parameters before making a connection using them, or alternatively turn off the warnings, so I can handle the errors myself? (by the way, ERRMODE_SILENT did not work)
I want my application to handle the errors, instead of displaying them in the output. This is a part of the constructor:
try {
$this->pdo = new PDO("mysql:host=$db_host;port=$db_port;dbname=$db_name", $db_user, $db_pass);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
} catch (PDOException $e){
$this->connEstablished = false;
$this->error = $e->getMessage();
}
Upvotes: 0
Views: 44
Reputation: 26
Check your 'display_errors' setting in php.ini. See the PHP configuration file documentation.
if 'display_errors' is 'On' then it will output any errors or warnings to the browser. Setting it to 'Off' will prevent this, and is almost always a good idea.
This is controlled via php.ini, but can also be changed at runtime using the built-in function ini_set
, which is useful if you do not have control over your environment (using a hosted server, etc.)
You can check the current value with ini_get('display_errors')
and turn it off with ini_set('display_errors', 'Off')
.
Upvotes: 1