jpfuentes2 / php-activerecord

ActiveRecord implementation for PHP
http://www.phpactiverecord.org/
Other
1.32k stars 443 forks source link

Dealing with PDO DB connection exception #512

Open ajanini opened 9 years ago

ajanini commented 9 years ago

When the PDO connection to the database fails, a PDOException is thrown that shows the password in plaintext (you can test this by typing an incorrect username or password).

I've tried setting PDO::ATTR_ERRMODE to PDO::ERRMODE_SILENT in Connection.php file, and that doesn't seem to help.

I've also tried to turn off PHP error reporting, but I can't seem to prevent the exception trace info printed to the browser.

Implementing try/catch blocks in every query seems very unpractical.

Have I overlooked something? How should I deal with this problem?

visavi commented 9 years ago

use $this -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

a good practice to turn off the production output of the error

for example, you can use this component https://github.com/vlucas/phpdotenv

ajanini commented 9 years ago

Hi @visavi, thanks for your help.

Could you give me some more info? For instance: I am calling a static method ::all(). I can't use $this in that context.

Also, I am trying to suppress the error. Shouldn't the option be PDO::ERRMODE_SILENT?

Invoking setAttribute is different than setting this option directly in Connection.php file? I've tried that with no luck.

Like I said, I've tried to turn off error reporting in PHP, but that error continues to be printed.

visavi commented 9 years ago

I think everything is clearly stated, I do not even know how to reassign https://github.com/jpfuentes2/php-activerecord/blob/b2ed6fc64ef35c88fd30d71091df0d0765719901/lib/Connection.php#L64

ajanini commented 9 years ago

I'm afraid I don't understand.

Like I said in my first post, I tried changing https://github.com/jpfuentes2/php-activerecord/blob/b2ed6fc64ef35c88fd30d71091df0d0765719901/lib/Connection.php#L66 to PDO::ERRMODE_SILENT.

This did not fix the problem.