Skip to content

Instantly share code, notes, and snippets.

@xShivan
Created July 22, 2014 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xShivan/8a08b03989ef93e26821 to your computer and use it in GitHub Desktop.
Save xShivan/8a08b03989ef93e26821 to your computer and use it in GitHub Desktop.
CodeIgniter model modified to use PDO Library
class CI_Model {
/**
* Constructor
*
* @access public
*/
private $pdo = null;
function __construct()
{
try
{
$pdo = new PDO('mysql:host=' . MYSQL_LOCALE . ';dbname=' . MYSQL_DB, MYSQL_USER, MYSQL_PASS,
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
catch(PDOException $e)
{
die ('DATABASE CONNECTION ERROR: ' . $e->getMessage());
}
log_message('debug', "Model Class Initialized");
}
/**
* __get
*
* Allows models to access CI's loaded classes using the same
* syntax as controllers.
*
* @param string
* @access private
*/
function __get($key)
{
$CI =& get_instance();
return $CI->$key;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment