0

After looking around most of last night and all of this morning, I find myself here.

I am looking to include a database connection within another class. From what I've read creating a connection within a class is bad? Can someone help me out or even point me in the direction of where I can find the relevant answer?

Thanks.

2
Contributors
3
Replies
17
Views
4 Years
Discussion Span
Last Post by pritaeas
0

From what I've read creating a connection within a class is bad?

Not necessarily. I would just pass a MySQLi or PDO object as a parameter to the class' constructor, and store it in a private variable.

0

So like this, providing I called me connection $mysqli?

class person {
  var $name;
  function __construct($mysqli, $persons_name) {
    $this->name = $persons_name;
  }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.