select('*', 'users', 'ID=4'); * var_dump($output); * * @package sven\sys\mysql * @copyright 2018 Ruben Meyer * @author Ruben Meyer * @version 0.1.0 * @see https://github.com/envms/fluentpdo * @see http://php.net/manual/de/class.pdo.php * */ class mysql { /** * instance * * Instance * * @access private * @static * @var resource (new self();) */ private static $instance = null; /** * connection * * PDO Connection * * @access private * @static * @var object|null Should contain the database connection */ private static $connection = null; /** * __construct * * Class constructor * * @access public * @return void */ public function __construct() { self::$instance = $this; $this->connect(); } /** * __destruct * * Class destructor * * @access public * @return void */ public function __destruct() { $this->disconnect(); } /** * getInstance * * returns Instance * * @access public * @return object */ public static function getInstance() { return self::$instance; } /** * getBuilder * * returns SQL Builder to query * * @access public * @return \Envms\FluentPDO\Query|\sven\sys\sven\uncallable */ public function getBuilder() { if(self::$connection !== null) return new \Envms\FluentPDO\Query(self::$connection); else { \sven\sys\core::addException(new \sven\sys\Exception("Exception", "Error: MySQL \$connection is NULL", 2002)); return new \sven\sys\sven\uncallable; } } /** * connect * * connects to our database * * @access private * @return void */ private function connect() { if(self::$connection) return; if(php_uname('r') === "6.1") { //if(false) { // development place @ school $data = (object) [ 'host' => '102-012', 'user' => 'intabi19', 'pass' => 'hallo', 'db' => 'sven' ]; } else { // development place @ home $data = (object) [ 'host' => '127.0.0.1', 'user' => 'root', 'pass' => '', 'db' => 'sven' ]; } try { if(mysqli_connect($data->host, $data->user, $data->pass)) { self::$connection = new \PDO('mysql:host='.$data->host.';dbname='.$data->db.';charset=utf8mb4', $data->user, $data->pass); self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); self::$connection->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ); } } catch (\Exception $e) { \sven\sys\core::addException(new \sven\sys\Exception($e)); } } /** * disconnect * * closes connection * * @access private * @return void */ private function disconnect() { if(gettype(self::$connection) == "object") self::$connection = null; } }; ?>