title: How can I use PDO in CodeIgniter 2?
body: <p>I would like to use PDO instead of the built-in database-classes. But how can I do it? I tried to do the modifications suggested in a <a href="http://christopherickes.com/web-app-development/using-pdo-in-codeigniter/" rel="noreferrer">blog post</a>. I commented out a part of <code>system\database\DB.php</code> and also added:</p>
  
  <pre><code>$DB = new PDO(
  $params['dbdriver'].':host='.$params['hostname'].';dbname='.$params['database'],
  $params['username'], $params['password']);
  
  return $DB;
  </code></pre>
  
  <p>But now my PHP-code crashes if I do <code>$this-&gt;load-&gt;database();</code> in a Controller. So how should I use PDO and execute database queries using PDO in CodeIgniter?</p>
  
  <p>I have also tried to use this code in a Controller: </p>
  
  <pre><code>foreach($this-&gt;db-&gt;query('SELECT * FROM users') as $row) {
      print_r($row);
  }
  </code></pre>
  
  <p>but it didn't work.</p>