Sorry if this is an easy or (possibly dumb) question, but I am a complete newbie to PHP and somewhat to OOP as well...
Using PDO, do i need to create a new PDO Object for each query? Or can I create one object that can then be passed to other classes and so on?
For example, I have the following line of code to create the object:
$db = new PDO($dsn, $user, $pass);
So now I have an instance of the PDO object stored as $db. Can that object now be used to run multiple statements? For instance if I have another object that needs database access so say the first attribute it requires is a PDO object, can I just pass this object on and then each new object instance just runs in own statement?
For example:
$user = new User($db, $userID);
$calendar = new Calendar($db, $userID);
Like I said, sorry if this seems obvious. I think I have the correct understanding, but I figured it is better safe that sorry. Thanks for everyones help!




Bookmarks