title: Convert MySQL database to JSON
body: <p>I'm using this code below to convert database to JSON.</p>
  
  <pre><code>&lt;?php
  header('Content-type:application/json');
  
  mysql_connect('localhost','root','')or die('cannot connect');
  mysql_select_db('sanpham');
  $sql = "SELECT * FROM cpu";
  $result = mysql_query($sql);
  if(!$result)
  {
      echo 'Lỗi SQL: '.mysql_error();
      echo "\r\n&lt;br /&gt;";
      echo 'SQL: '.$sql;
      exit;
  }
  $rows = array();
  while($row=mysql_fetch_array($result)){
      $rows[]=$row;
  }
  echo json_encode($rows);
  
  
  ?&gt;
  </code></pre>
  
  <p>In my PHP file no error, no database, nothing display.</p>