Skip to content

Commit

Permalink
modified base query clas and connections
Browse files Browse the repository at this point in the history
  • Loading branch information
gurpreetkaits committed Oct 30, 2023
1 parent 8276f4e commit 579bb38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Query
protected $limit;
protected $offset;

protected PDO $pdo;
protected PDO|Connection $pdo;
public function __construct(
PDO|Connection $connection
) {
Expand Down

0 comments on commit 579bb38

Please sign in to comment.