PDO isn't working on PHP and MySql -


i have amazon ec2 instance (amazon linux) setup lamp installed. trying out following example, seems not working, outputs "test" in browser , no error or no other output. have doubt pdo isn't enabled php , how find out ? have enabled mysql , mysql_pdo extensions in php.ini

function getdb() {     $dbhost = "localhost";     $dbuser = "abc";     $dbpass = "abc123";     $dbname = "test";      $mysql_conn_string = "mysql:host=$dbhost;dbname=$dbname";      try{         $dbconnection = new pdo($mysql_conn_string, $dbuser, $dbpass);      }     catch(pdoexception $ex) {          echo($ex->getmessage());     }      return $dbconnection; }  echo("test"); $db = getdb();  try {     //connect appropriate above     $db->query('hi'); //invalid query! } catch(pdoexception $ex) {     echo "an error occured!"; //user friendly message     echo($ex->getmessage()); } 

create test file caled test.php , write

<?php phpinfo(); ?>

and open page in browser , line containing pdo.

assuming have found pdo line please check pdo drivers see if mysql supported driver. or can place code below in same file , check it

<?php print_r(pdo::getavailabledrivers()); ?>

other solutions check pdo availability can

<?php if (!defined('pdo::attr_driver_name')) { echo 'pdo unavailable'; } ?> 

or

<?php     var_dump(extension_loaded('pdo' )); //should return boolean value     var_dump(extension_loaded('pdo_mysql')); //should return boolean value     var_dump(get_loaded_extensions()); ?> 

or using command line

$ php -m


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -