Lodius2000 Posted February 16, 2009 Share Posted February 16, 2009 instantiation (I think I spelled that right) any way, as far as I can tell Pear db self instantiates, meaning there is not line (that I type) that says $db = new db; heres my login script as an example <?php include('path/to/pear/db.php'); $user = '**********'; $password = '*********'; $hostspec = 'localhost'; $database = ''*********'; $phptype = 'mysql'; $dsn = "$phptype://$user:$password@$hostspec/$database"; //establish the connection $db =& DB::connect($dsn); if (DB::isError($db)){ die ($db->getMessage()); } ?> this works fine and uses methods of the db object, but I have not made an object called $db from any class....How does it work? Quote Link to comment https://forums.phpfreaks.com/topic/145362-solved-pear-db-self-instantiation/ Share on other sites More sharing options...
Lodius2000 Posted February 16, 2009 Author Share Posted February 16, 2009 I know $database has an extra single quote in it... I spotted it too late to edit, please disregard Quote Link to comment https://forums.phpfreaks.com/topic/145362-solved-pear-db-self-instantiation/#findComment-763094 Share on other sites More sharing options...
trq Posted February 16, 2009 Share Posted February 16, 2009 DB::connect() is a static method which returns a database object as defined by the $dsn string passed to it. Quote Link to comment https://forums.phpfreaks.com/topic/145362-solved-pear-db-self-instantiation/#findComment-763282 Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 See explanation of design patterns in PHP manual to see similar technique used. Quote Link to comment https://forums.phpfreaks.com/topic/145362-solved-pear-db-self-instantiation/#findComment-763310 Share on other sites More sharing options...
Lodius2000 Posted February 16, 2009 Author Share Posted February 16, 2009 Thanks guys, Im learing oop and that makes sense solved Quote Link to comment https://forums.phpfreaks.com/topic/145362-solved-pear-db-self-instantiation/#findComment-763561 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.