title: json does not work with pdo but it works with mysql_ function
body: <p>This code works 100% but when I try to use <code>JSON</code> it does not display any data.</p>
  
  <p>The problem is that I am trying to change all my codes to <code>PDO</code> since I was told that <strong><em><code>mysql_*</code></em></strong> function's are depreciated. </p>
  
  <pre><code>&lt;?php
  $con = new PDO('mysql:host=localhost;dbname=adnan;charset=UTF-8','root','');
  $sql= $con-&gt;query('select *  from adnan_user');
  while($row =$sql-&gt;fetch()){
      echo $row['user_id'],"\n";
  }
  ?&gt;
  </code></pre>
  
  <p>Here is the code which I call in <code>json</code> : its also works when I use <strong><em><code>mysql_</code></em></strong> function 
  But with <strong><em><code>pdo</code></em></strong> it does not work .</p>
  
  <pre><code>&lt;?php 
  $con = new PDO('mysql:host=localhost;dbname=adnan;charset=UTF-8','root','');
  $sql= $con-&gt;query('select *  from adnan_user');
  while($row =$sql-&gt;fetch()){
      $name = $row['name'];
      $user= $row['user']; 
  }
  // The JSON standard MIME header.
  header('Content-type: application/json');
  $array = array('name'=&gt;$name, 'user'=&gt;$user);
  echo  json_encode($array);
  ?&gt;
  </code></pre>
  
  <p>The code for json </p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
          &lt;script&gt; 
          $(document).ready(function(){
              $.getJSON('json.php', function(data) {
                  $('#myJson').html('&lt;table style="color:red"&gt;&lt;tr&gt;&lt;td&gt;' + data.name + '&lt;/td&gt;&lt;td&gt;' + data.user + '&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;');
              });
          });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="myJson"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>