php - extending PDO as CodeIgniter library -


i know ci 2.1.3 support pdo. it'll more comfortable me using pdo functions instead of codeigniter function, , want extend pdo , use library , create pdo object once loaded controller or library; possible, isn't it?, attempt far:

class mypdo extends pdo {   public function __construct($dsn='mysql:dbname=mydbname;host=localhost',                               $username='myusername',                               $password='mypassword',                               $driver_options=array()) {         parent::__construct($dsn, $username, $password, $driver_options);   } } 

and simple usage:

class otherlibrary{    var $ci;    var $something_id;     public function __construct(){       $this->ci =& get_instance();       $this->ci->load->library('mypdo');        $this->something_id = 'foo';    }     public function is_something_exist(){       try{          $q = "select * something_id = '$this->something_id'";          $stmt = $this->ci->mypdo->prepare($q); //<--problem          $stmt->execute();           if ($stmt->rowcount() < 1){             return false;           } else {             return true;           }        } catch (pdoexception $e){            echo $e->getmessage();        }     } } 

always return:

fatal error: call member function prepare() on non-object in...

i'm not expert @ in php class/object, please need improve code , make works. thanks.

according codeigniter libraries documentation:

  • file names must capitalized. example: myclass.php class

  • declarations must capitalized. example: class myclass

  • class names , file names must match.

make sure mypdo class application/library/mypdo.php.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -