php - My openshift application PDO query didn't work -
i seek connect phpmyadmin database using php script in openshift
but result empty page.
then, find question query didn't work
but don't know why
there original code
try{ $dsn = 'mysql:dbname=exampledatabase;host=127.**.***.***;port=*****'; $dbh = new pdo($dsn, "account", "password"); $sth = $dbh->prepare('select * test1'); $fin = $sth->execute(); while($row = $sth->fetch(pdo::fetch_assoc)){ print_r($row); } } grab (pdoexception $e){ echo "sytan error" . $e -> getmessage(); } $dbh = null;
and result empty page, modify code
there modify code
try{ $dsn = 'mysql:dbname=exampledatabase;host=127.**.***.***;port=*****'; $dbh = new pdo($dsn, "account", "password"); $sth = $dbh->prepare('jngfcjfgcnmgcm,,hmnxf'); $fin = $sth->execute(); while($row = $sth->fetch(pdo::fetch_assoc)){ print_r($row); } } grab (pdoexception $e){ echo "sytan error" . $e -> getmessage(); } $dbh = null;
i input wrong query sytanx(jngfcjfgcnmgcm,,hmnxf), didn't homecoming error.
add script see errors
error_reporting(e_all | e_strict); ini_set('display_errors',1); ini_set('html_errors', 1);
and alter query code this, see notes
try{ //port=***** need different default $dsn = 'mysql:host=localhost;dbname=exampledatabase'; $options = array(pdo::attr_errmode => pdo::errmode_exception); $dbh = new pdo($dsn, "account", "password", $options); $sth = $dbh->prepare('select * test1'); // execute $sth $sth->execute(); //change fetch fetchall while($row = $sth->fetchall(pdo::fetch_assoc)){ print_r($row); } } grab (pdoexception $e){ echo "sytan error" . $e->getmessage(); }
php mysql pdo openshift
No comments:
Post a Comment