Skip to content

Commit 09d4784

Browse files
committed
basic getAll method
Signed-off-by: Derek Smart <derek@grindaga.com>
1 parent d692791 commit 09d4784

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Model.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
<?php
22
namespace PHPRed;
33

4-
class Model extends PHPRed
4+
abstract class Model extends PHPRed
55
{
6+
public $model;
7+
public $table;
8+
69
public function __construct(\mysqli $mysqli)
710
{
811
parent::__construct($mysqli);
912
}
13+
14+
public function getAll()
15+
{
16+
$query = "SELECT * FROM $this->table;";
17+
$results = $this->mysqli->query($query);
18+
return $this->toArray($results);
19+
}
1020
}

src/PHPRed.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?php
22
namespace PHPRed;
33

4-
class PHPRed
4+
abstract class PHPRed
55
{
6-
private $mysqli;
6+
protected $mysqli;
77

88
public function __construct(\mysqli $mysqli)
99
{
1010
$this->mysqli = $mysqli;
1111
}
12+
13+
protected function toArray(\mysqli_result $results) : array
14+
{
15+
return $results->fetch_array(MYSQLI_ASSOC);
16+
}
1217
}

0 commit comments

Comments
 (0)