-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added interface
ResultInterface
that all database providers use as …
…return type for queries
- Loading branch information
1 parent
6ddbbce
commit fc17474
Showing
6 changed files
with
79 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Framework\Database; | ||
|
||
interface DatabaseInterface | ||
{ | ||
/** Open connection to the DB */ | ||
public function connect(): void; | ||
|
||
/** Close the open connection */ | ||
public function disconnect(): void; | ||
|
||
/** Execute the given query */ | ||
public function unprepared(string $query): ResultInterface|false; | ||
|
||
/** Execute the given prepared statement */ | ||
public function prepared(string $query, string $colTypes, ...$values): ResultInterface|false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Framework\Database; | ||
|
||
use mysqli_result; | ||
|
||
class MariaDbResult implements ResultInterface | ||
{ | ||
public function __construct( | ||
private mysqli_result|false $result, | ||
) { | ||
} | ||
|
||
public function fetch(): array|false | ||
{ | ||
if ($this->result === false) { | ||
return false; | ||
} | ||
|
||
$row = $this->result->fetch_assoc(); | ||
if ($row === null) { | ||
return false; | ||
} | ||
return $row; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Framework\Database; | ||
|
||
interface ResultInterface | ||
{ | ||
public function fetch(): array|false; | ||
} |