[eluser]jvicab[/eluser]
Actualy it is quite easy. try this:
1- Create a file (like pdodb.php) inside application/library folder an copy this code on it:
Code:
class PDOdb
{
private static $_pdo;
public static function getInstance()
{
if (self::$_pdo === null) {
$CI =& get_instance();
$host = $CI->db->hostname;
$dbname = $CI->db->database;
$user = $CI->db->username;
$password = $CI->db->password;
$dsn = 'mysql:dbname='.$dbname.';host='.$host;
try {
self::$_pdo = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
self::$_pdo = null;
}
}
return self::$_pdo;
}
}
2- Use it as any other library, like:
Code:
$this->load->library('PDOdb'); // or better get it autoloaded in config/autoload.php
$db = PDOdb::getInstance();
// use it, like:
$query = "SELECT * FROM mytable WHERE id = :id";
$q = $db->prepare($query);
$q->bindParam(':id', $_POST['id']);
if ($q->execute()) {
while ($row = $q->fetch()) {
......
}
}
Good luck!