mysql - PHP Does not show errors when trying to connect to a wrong database using PDO -
i'm pretty new php , i'm having basic problem haven't found solution despite looking through similar questions in forum.
i'm trying connect php database (mysql) through pdo. if enter wrong username or password php show error in browser if enter wrong database name doesn't retireve errors. how possible? code follows:
<?php try{ $conn = new pdo('mysql:127.0.0.1;dbname=mydb','root','root'); $conn -> setattribute(pdo::attr_errmode, pdo::errmode_exception); } catch(pdoexception $e){ echo 'wrong credentials'; }
my php.ini file configured show errors , apache restarted after modifying following values:
error_reporting = e_all | e_strict display_errors = on display_startup_errors = on log_errors = on
i tried use following code @ begining of script still doesn't show errors related wrong database name
ini_set('display_errors', 1); error_reporting(~0);
thanks lot in advance help, i'm sure pretty stupid thing can't figure out.
this turned quite tricky bug find , explain though quite simple.
the issue dsn string incorrect.
current value: 'mysql:127.0.0.1;dbname=mydb'
it should be: 'mysql:host=127.0.0.1;dbname=mydb'
note: host=
missing.
however, pdo not validate dsn parameter string correctly , connects database without error.
however, has ignored dbname
parameter, when try query error of: 1046 no database selected'
.
Comments
Post a Comment