Few years ago, I read some comment in local PHP community that establishing multiple Database Connection (when using mysqli) might cause the problem. At that time, of course that I didn't understand the actual reason of why, however I sense that its actually might be a problem, not an fatal kind error, but performance kind. (whether is right or wrong..)
Now I'm using PDO and the idea that 'you are not allow to creating multiple db connection in any manner' still suffering me.
I want to know that is really bad idea that referencing same PDO object in multiple object.
class IHavePDO {
$adaptor;
public function __construct(PDO $pdo) {
$this->adaptor = $pdo;
}
public function save() {
// Do something with $this->adaptor
}
}
- [tail]
I know that it can be avoided using Data Mapper Pattern. (still learning) But can't figure out how can I make the same
$objIHavePDO->save()
method works, not passing the object as parameter for mapper class like$mapper->save($objIHavePDO)
.