There is a class:

class list_control { private $lang; private $dbc = $dbc; function __construct($lang) { $this->lang = $lang; loadModule('mysql_PDO'); } public function start() { $db = new mysql_PDO($this->dbc['host'], $this->dbc['user'], $this->dbc['password'], $this->dbc['dbase']); $db->connect(); $db->query('SELECT * FROM slug'); load('list', $this->lang); $db = null; } } 

$ dbc - Array with connection data in DB. Located in the config.php, which is connected to index.php, and in this index.php there is a file with this class. It is necessary to do so as not to violate the pattern.

  • Global $ dbc. And this is a bad pattern. - u_mulder

1 answer 1

It would be more correct to pass this array as a parameter to the start method.

Well, wrong - you can use the directive global

 public function start() { global $dbc; $db = new mysql_PDO($dbc['host'], $dbc['user'], $dbc['password'], $dbc['dbase']); $db->connect(); 
  • Thank! I’ll rather get global, because I don’t make a switch to every page at index, so that start methods are called differently - Ivaan
  • If my answer helped you, mark it as correct - Anton Shchyrov