title: replace/migrate old mysql syntax with PDO in PHP
body: <p>I'm learning how to access mysql db from php, and i saw a basic code (following) with mysql commands, however i realize that those syntaxis are old and it's better to use mysqli or PDO. I readed about it and i think that PDO is the way, so i appreciate any help on how to migrate this to PDO:</p>
  
  <p>1) Connect to mysql database</p>
  
  <pre><code> include 'DB.php';
   $con = mysql_connect($host,$user,$pass);
   $dbs = mysql_select_db($databaseName, $con);
  </code></pre>
  
  <p>2) Query database for data</p>
  
  <pre><code> $result = mysql_query("SELECT * FROM $tableName");          //query
   $array = mysql_fetch_row($result);                          //fetch result    
  </code></pre>
  
  <p>3) echo result as json </p>
  
  <pre><code> echo json_encode($array);
  </code></pre>