title: Preparing simple query for PDO connection
body: <p>I would like to prepare PDO statement and convert results to JSON in PHP. I managed to connect to database by following method:</p>
  
  <pre><code>class DB_CONNECT {
  
  function __construct() {
      $this-&gt;connect();
  }
  
  function __destruct() {
      $this-&gt;close();
  }
  
  function connect() {
      $root = getenv("DOCUMENT_ROOT"); 
      require_once ($root.'/db/db_config.php');
  
      try
      {
          $db = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_DATABASE.';charset=utf8;port='.DB_PORT, DB_USER, DB_PASSWORD);
          $db-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
          $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          echo 'OK';
          return $db;
      }
      catch (PDOException $e)
      {
          print "Connection error!: " . $e-&gt;getMessage() . "&lt;br/&gt;";
          die();
      }
  
  }
  
  function close() {
  
      $db = null;
  }
  </code></pre>
  
  <p>PHP, where I make statements looks like this:</p>
  
  <pre><code>$root = getenv("DOCUMENT_ROOT"); 
  require_once ($root.'/db/db_connect.php');
  
  $db = new DB_CONNECT();
  
  $statement=$db-&gt;prepare("SELECT name, surname FROM lecturer");
  $statement-&gt;execute();
  $results=$statement-&gt;fetchAll(PDO::FETCH_ASSOC);
  echo json_encode($results);
  </code></pre>
  
  <p>When I run this PHP, I'm getting only OK message, that the connection went successfully. What's wrong with that query code?</p>