Connection to MySQL database - Robust and clean

<?php Namespace Connection; class MysqliConnector { /** * Return connection settings. * * @return config */ private $config; /** * The active MySQLi connection. * * @var MYSQLI */ private $mysqli; /** * Return connection settings. * * @return config */ public function __construct(array $config) { $this->config = $config; return $this; } /** * Create a new database connection instance. * * @return MYSQLI */ public function mysqli() { $this->mysqli = new \mysqli($this->config['host'], $this->config['username'], $this->config['password'], $this->config['database']); return $this->mysqli; } }
Simple connection system with MySQL database, object-oriented. cleanly and robustly, leaving our reusable code to make connections with different database using the mylsqi driver.

Recommended for connections only with MySQL and for those who want more performance.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.