[eluser]Abel A.[/eluser]
DB config:
Code:
$active_group = 'default';
$active_record = FALSE;
$db['default']['hostname'] = 'mysql:host=localhost';
$db['default']['username'] = 'db_user';
$db['default']['password'] = 'password';
$db['default']['database'] = 'db_table';
$db['default']['dbdriver'] = 'pdo';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Simple select:
Code:
$myuserid = 10;
$sql = "SELECT userid, name, email
FROM table_users
WHERE userid = :userid
LIMIT 1";
$stmt = $this->db->conn_id->prepare($sql);//prepare the query
$stmt->bindParam(':userid', $myuserid, PDO::PARAM_STR);//assign params
$stmt->execute();//execute query
$userinfo = $stmt->fetch();
//user the data
echo $userinfo['name'];
echo $userinfo['email'];
Insert:
Code:
$sql = "INSERT INTO table_strikes (striketime,ip_address,userid)
VALUES (:striketime,:ip_address,:userid)";
$stmt = $this->db->conn_id->prepare($sql);
$stmt->bindParam(':striketime', now(), PDO::PARAM_STR);
$stmt->bindParam(':ip_address', $this->input->ip_address(), PDO::PARAM_STR);
$stmt->bindParam(':userid', $myuserid, PDO::PARAM_STR);
$stmt->execute();
You need to load the database before running any queries:
Code:
$this->load->database();
Here's more things you can do with pdo:
http://php.net/manual/en/book.pdo.php
So far I only used fetch() in the first example, but you can visit php.net for more info.
All CI does is load the PDO class. CI does NOT rewrite the pdo class, it only connects to the database per your db configuration. You use pdo like you would in any php application. Hence why there really isn't much info on pdo here in CI.
Hope that helps.