Created
July 22, 2014 08:39
-
-
Save xShivan/8a08b03989ef93e26821 to your computer and use it in GitHub Desktop.
CodeIgniter model modified to use PDO Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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