Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
Commitf9e2090a1028712ecc6e1b0c71390c821689b414 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-04-01 09:43:48 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-04-01 09:43:48 +0300
Filesfed1608498f34299d7e3039cf3290c81e3e84875 /src
devrix-job-board-f9e2090a1028712ecc6e1b0c71390c821689b414.tar
devrix-job-board-f9e2090a1028712ecc6e1b0c71390c821689b414.tar.gz
devrix-job-board-f9e2090a1028712ecc6e1b0c71390c821689b414.zip
Parente9ba7fbcff47f0e4a03d74b857e9864d67a8b163 (diff)
Implemented getById from DB and changed some method names
3 files changed, 22 insertions, 4 deletions
-rw-r--r--src/index.php8
-rw-r--r--src/models/DB.php7
-rw-r--r--src/models/JobOffer.php11
diff --git a/src/index.php b/src/index.php
index ecebcd9..55bba39 100644
--- a/src/index.php
+++ b/src/index.php
@@ -3,8 +3,12 @@
include_once("models/JobOffer.php");
$jb = new JobOffer("Test", "A test", "TheTest", 11);
- JobOffer::insertInDB($jb);
- foreach(JobOffer::getAll() as $key => $obj) {
+ // JobOffer::insertInDB($jb);
+ foreach(JobOffer::getAllFromDB() as $key => $obj) {
echo "{$obj->id} {$obj->title}<br>";
}
+ echo "<br>";
+
+ $gottenjb = JobOffer::getFromDBById(1);
+ echo $gottenjb->title;
?>
diff --git a/src/models/DB.php b/src/models/DB.php
index 299b05a..b973e4b 100644
--- a/src/models/DB.php
+++ b/src/models/DB.php
@@ -37,6 +37,13 @@ class DB {
$this->connection->exec($query);
}
+ function getById(string $tableName, int $id) {
+ $sth = $this->connection->prepare("SELECT * FROM `{$tableName}` WHERE id = {$id}");
+ $sth->execute();
+
+ return $sth->fetch(PDO::FETCH_OBJ);
+ }
+
function getAllValues(string $tableName) {
$sth = $this->connection->prepare("SELECT * FROM `{$tableName}`");
$sth->execute();
diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php
index 7603211..3bb1791 100644
--- a/src/models/JobOffer.php
+++ b/src/models/JobOffer.php
@@ -20,13 +20,20 @@ class JobOffer extends DBModel {
}
/**
+ * @return JobOffer
+ */
+ static function getFromDBById(int $id) {
+ return self::$DB->getById(self::TABLE_NAME, $id);
+ }
+
+ /**
* @return JobOffer[]
*/
- static function getAll() {
+ static function getAllFromDB() {
return self::$DB->getAllValues(self::TABLE_NAME);
}
- static function insertInDB(JobOffer $jb) {
+ static function insertIntoDB(JobOffer $jb) {
self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary);
}
}