I recently needed to use a custom database table in a ProcessWire site since I needed to streamline the performance. ProcessWire comes with an in-built database variable that allows you to perform prepared statements as below:
$result = \ProcessWire\wire('database')->prepare('SELECT * from `table` where `id` > :id');
$result->execute([':id' => 999]);
while ($row = $result->fetchAll()) {
print_r($row);
}
Note: with PHP, when using prepared statements you can only use fetchAll
on the results set, which returns numerical and associative arrays together.
