diff options
author | Thedro Neely <thedroneely@gmail.com> | 2018-08-30 04:30:53 -0400 |
---|---|---|
committer | Thedro Neely <thedroneely@gmail.com> | 2018-08-30 04:30:53 -0400 |
commit | 2bdcd9d9283b44e7c35822aa1317013928006fd8 (patch) | |
tree | ca2bf097e4dfcfdabba36a5cb2643560ab03b926 /bootstrap/database | |
download | thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.tar.gz thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.tar.bz2 thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.zip |
Initialize Repo: First Commit
Diffstat (limited to 'bootstrap/database')
-rw-r--r-- | bootstrap/database/Connection.php | 18 | ||||
-rw-r--r-- | bootstrap/database/QueryBuilder.php | 31 |
2 files changed, 49 insertions, 0 deletions
diff --git a/bootstrap/database/Connection.php b/bootstrap/database/Connection.php new file mode 100644 index 0000000..deec2c6 --- /dev/null +++ b/bootstrap/database/Connection.php @@ -0,0 +1,18 @@ +<?php + +class Connection +{ + public static function make($config) + { + try { + return new PDO( + $config['connection'].';dbname='.$config['name'], + $config['username'], + $config['password'], + $config['options'] + ); + } catch (PDOException $e) { + error_log($e->getMessage()); + } + } +} diff --git a/bootstrap/database/QueryBuilder.php b/bootstrap/database/QueryBuilder.php new file mode 100644 index 0000000..a814ed3 --- /dev/null +++ b/bootstrap/database/QueryBuilder.php @@ -0,0 +1,31 @@ +<?php + +class QueryBuilder +{ + protected $pdo; + + public function __construct($pdo) + { + $this->pdo = $pdo; + } + + public function selectAll($table, $intoClass) + { + $statement = $this->pdo->prepare("select * from {$table}"); + $statement->execute(); + return $statement->fetchAll(PDO::FETCH_CLASS, $intoClass); + } + + public function insert($table, $data) + { + $sql = sprintf( + 'insert into %s (%s) values (%s)', + $table, + implode(', ', array_keys($data)), + ':' . implode(', :', array_keys($data)) + ); + + $statment = $this->pdo->prepare($sql); + $statment->execute($data); + } +} |