title: Why i got in PDO always boolean error?
body: <p>I have a mySQL class to connect and execute my queries from and in to a database. When i connect to the database everything is working correctly. When i try to put something into the database, then it's also ok, but when i try to get something from it, I get a boolean (true) error, regardless the input. I assume it must return an object but it returns a boolean. Why is that so?</p>
  
  <p>My code is shown below:</p>
  
  <pre><code>class Database {
  
  function __construct() { 
      // пустой инициализатор 
  
      $this-&gt;set_connection(); // нужно ли автоматически инициализировать?
  }
  
  private $dbchar = "UTF8";
  private $dbuser = "admin";
  private $dbpass = "1234";
  private $dbhost = "localhost";
  private $dbname = "core_db";
  private $dbpref = "pre_";
  
  private $link;
  
  private function set_connection() {
  
      $dsn = "mysql:host=".$this-&gt;dbhost.";dbname=".$this-&gt;dbname.";charset=".$this-&gt;dbchar;
  
      $opt = array(
          PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
          //PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
          PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_OBJ,
          // Выключает режим эмуляции! если у вас проблемы с LIMIT ?,?
          PDO::ATTR_EMULATE_PREPARES   =&gt; TRUE
      );
      try {
          $this-&gt;link = new PDO($dsn, $this-&gt;dbuser, $this-&gt;dbpass, $opt);
          if (!$this-&gt;link) throw new Exception("Cannot connect to database!", 4);
  
      } catch (Exception $e) {
          die("Error! " . $e-&gt;getMessage());
      }
  }
  
  // Получаем ссылку на соединенние с базой 
  
  function get_connection() {
  
      return $this-&gt;link; 
  }
  
  /*
      НЕ УДАЛЯТЬ ---------------------------------------------------------
      Запросы можно использовать вот так.................!
      # просто испольняет SQL запрос // INSERT. DELETE OR UPDATE
      $this-&gt;execute_query($sql); 
      $this-&gt;execute_query($sql, $data);  
      # all rows
      $result = $this-&gt;execute_query($sql, $data)-&gt;fetchAll();
      foreach ($result as $row) echo $row['name'];
      # one row
      $row = $this-&gt;execute_query($sql, $data)-&gt;fetch();
      # one cell
      $count = $this-&gt;execute_query($sql)-&gt;fetchColumn(); // можно использовать для подсчета ячеекы
      # column
      $ids = $this-&gt;execute_query($sql)-&gt;fetchAll(PDO::FETCH_COLUMN);
      НЕ УДАЛЯТЬ ---------------------------------------------------------
  */
  
  // метод выполнения запроса SQL !!!
  // Использ.  $sql = SELECT * FROM table WHERE a = ? and b = ?
  // Использ.  $data = array('a', 'b');
  
  function execute_query($sql, $elements=false) {
  
      $error_exist = false;
      $data = false;
  
      try {
          if (empty($sql)) throw new RuntimeException('no SQL!');
  
          $stmt = $this-&gt;get_connection()-&gt;prepare($sql);
  
          if (!$stmt) throw new RuntimeException('SQL preparing failure!');
  
          if (!$elements) {
              $data = $stmt-&gt;execute();
          } else {
              $data = $stmt-&gt;execute($elements);
          }
  
          if (!$data) throw new RuntimeException('SQL execution failure!');
  
      } catch (Exception $e) {
          $error_exist = true;
          $data = $e-&gt;getMessage();
      }
  
      return array('error' =&gt; $error_exist, 'result' =&gt; $data);
  }
  
  
  
  // Закрываем соединение с базой
  function close_connection() {
      $this-&gt;link = null;
  }
  
  function __destructor() {
      $this-&gt;close_connection();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The <code>index.php</code> file itself is shown here instead:</p>
  
  <pre><code>$sql = "SELECT * FROM prava WHERE test_id = ?";
  
  $r = $db-&gt;execute_query($sql, ['1']);
  
  var_dump($r);
  </code></pre>