diff --git a/src/Connection.php b/src/Connection.php index fbd4063..d6b9da3 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -8,17 +8,25 @@ class Connection { + private static $database; + private static $host; + private static $user; + private static $password; + public function __construct( array $config ) { - if(!in_array('database',$config) && !in_array('hostname',$config) && !in_array('username',$config)){ + if (!in_array('database', $config) && !in_array('hostname', $config) && !in_array('username', $config)) { return new Exception('all keys required database,hostname,username cannot be empty'); } - // $connection = $config['connection'] ?: 'mysql'; - $database = $config['database']; - $host = $config['hostname']; - $user = $config['username']; - $password = $config['password'] ?: ''; - return (new Mysql($host, $database, $user, $password))->connect(); + self::$database = $config['database'] ?: 'test'; + self::$host = $config['hostname'] ?: 'localhost'; + self::$user = $config['username'] ?: ''; + self::$password = $config['password'] ?: ''; + } + + public static function connect() + { + return (new Mysql(self::$host, self::$database, self::$user, self::$password))->connect(); } } diff --git a/src/Query.php b/src/Query.php index ab63b76..e8548de 100644 --- a/src/Query.php +++ b/src/Query.php @@ -20,7 +20,7 @@ class Query protected $limit; protected $offset; - protected PDO $pdo; + protected PDO|Connection $pdo; public function __construct( PDO|Connection $connection ) {