mysql pdo connection strings -
i'm learning pdo , need know if connection (it works) secure. put connections in inaccessible folder outside of root.
is formed or can improve it?
do need $conn->setattribute
...exception?
$user = 'joeuser'; $pass = 'joespassword'; try { $conn = new pdo("mysql:host=mywebhost.com;dbname=mydatabase", $user, $pass); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); } catch(pdoexception $e) { echo 'error: ' . $e->getmessage(); }
if connection (it works) secure.
of course not
you revealing database internals in case of error. 1 call "secure".
do need $conn->setattribute...exception?
yes.
can improve it?
for strange reason setting username , password variables. database? other configurable stuff?
, of course have rid of try .. echo
stuff
$user = 'joeuser'; $pass = 'joespassword'; $host = 'mywebhost.com'; $db = 'mydatabase'; $charset = 'utf8'; $conn = new pdo("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);
while these configuration options can detached , stored in config file
Comments
Post a Comment