Display all that would be secret while Mysql is broken

fomalhaut

Member
Messages
107
Reaction score
0
Points
16
Hello.

While the Mysql update, if I try to connect my website, I got a (normal) error.

What must I change for not display secret things, like user, password ? Here is the message I have :
<br />
<b>Fatal error</b>: Uncaught exception 'PDOException' with message 'SQLSTATE[42000] [1044] Access denied for user 'usr_ident'@'int.chopin.x10hosting.com' to database 'usr_dbName'' in /home/usr/public_html/repinc/DBase.inc:4
Stack trace:
#0 /home/usr/public_html/repinc/DBase.inc(4): PDO-&gt;__construct('mysql:host=loca...', 'usr_ident', 'password')
#1 /home/usr/public_html/index.php(5): include('/home/usr/publi...')
#2 {main}
thrown in <b>/home/usr/public_html/repinc/DBase.inc</b> on line <b>4</b><br />
(naturelly, I've masked the real user, password ecc. by usr, ident, dbName...)

Thanks if you can help me.
 

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
Hello.

While the Mysql update, if I try to connect my website, I got a (normal) error.

What must I change for not display secret things, like user, password ? Here is the message I have :
(naturelly, I've masked the real user, password ecc. by usr, ident, dbName...)

Thanks if you can help me.

So that is why you have to define the variables separately not in the connect statement like

PHP:
$username="database_username";
$password="password";
$database="database_name";
$databasehost = "localhost";

mysql_connect($databasehost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

So even it shows the error line it shows only this
mysql_connect($databsehost,$username,$password);
 
Last edited:

fomalhaut

Member
Messages
107
Reaction score
0
Points
16
That's so simple !!! :redface:

I'll do that asap.

Thank you very much Gsonline
 

as4s1n

New Member
Messages
174
Reaction score
4
Points
0
You know, I tried that, but when I tried that (using PDO) it still showed my information. So I just put under the catch statement a function that writes the error to a file and displays custom error text I.E. "Cannot connect to server."
 
Last edited:

fomalhaut

Member
Messages
107
Reaction score
0
Points
16
As4s1n : That's exactly what I've done too, because in fact, PDO translate the variables to their values.

No problem.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Catching the exception is the only way, but you can make it easier .

PHP:
class LocalDB extends PDO {
    static $dbs = array();

    static function connect($db='dflt') {
        if (! isset(self::$dbs[$db])) {
            try {
                self::$dbs[$db] = new PDO("mysql:hostname=localhost;dbname=$db", 'user', 'passwd');
            } catch (PDOException $exc) {
                // erase frame w/ password from call trace.
                throw new PDOException($exc->getMessage(), $exc->getCode(), $exc->getPrevious());
            }
            self::$dbs[$db]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        }
        return self::$dbs[$db];
    }
}
RAII support left as an exercise.
 
Last edited:
Top