GermaniaKG /
Worlds
| 1 | <?php |
||||
| 2 | namespace Germania\Worlds; |
||||
| 3 | |||||
| 4 | use Germania\Worlds\Exceptions\DatabaseException; |
||||
| 5 | |||||
| 6 | class PdoWorlds extends Worlds implements WorldsInterface |
||||
| 7 | { |
||||
| 8 | public $worlds = array(); |
||||
| 9 | |||||
| 10 | public $worlds_table = "germania_world"; |
||||
| 11 | |||||
| 12 | /** |
||||
| 13 | * @param \PDO $pdo PDO Instance |
||||
| 14 | * @param WorldInterface|null $world WorldsInterface instance result template (optional) |
||||
| 15 | * @param [type] $worlds_table Custom table name (optional) |
||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||
| 16 | */ |
||||
| 17 | public function __construct( \PDO $pdo, WorldInterface $world = null, $worlds_table = null ) |
||||
| 18 | { |
||||
| 19 | $this->worlds = new \ArrayObject; |
||||
| 20 | $this->worlds_table = $worlds_table ?: $this->worlds_table; |
||||
| 21 | |||||
| 22 | // ID is listed twice here in order to use it with FETCH_UNIQUE as array key |
||||
| 23 | $sql = "SELECT |
||||
| 24 | id, |
||||
| 25 | id AS id, |
||||
| 26 | world_name AS name, |
||||
| 27 | world_description AS description, |
||||
| 28 | world_url AS slug, |
||||
| 29 | world_photo AS photo |
||||
| 30 | |||||
| 31 | FROM {$this->worlds_table} |
||||
| 32 | WHERE is_active > 0"; |
||||
| 33 | |||||
| 34 | $stmt = $pdo->prepare( $sql ); |
||||
| 35 | |||||
| 36 | $stmt->setFetchMode( \PDO::FETCH_CLASS, $world ? get_class($world) : World::class ); |
||||
|
0 ignored issues
–
show
$world ? get_class($worl...nia\Worlds\World::class of type string is incompatible with the type integer expected by parameter $columnNumber of PDOStatement::setFetchMode().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 37 | |||||
| 38 | if (!$stmt->execute()): |
||||
| 39 | throw new DatabaseException("Could not retrieve Worlds from database"); |
||||
| 40 | endif; |
||||
| 41 | |||||
| 42 | $this->worlds = $stmt->fetchAll(\PDO::FETCH_UNIQUE); |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | |||||
| 46 | } |
||||
| 47 |