Search the blog

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.

View the full details of the $database variable.

Tim Bennett is a web designer and developer. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.