$database->execute() method

Execute a PDO statement, with retry and error handling

Given a PDOStatement ($query) this method will execute the statement and return true or false as to whether it was successful.

Unlike other PDO methods, this one (native to ProcessWire) will retry queries if they failed due to a lost connection. By default it will retry up to 3 times, but you can adjust this number as needed in the arguments.


// prepare the query
$query = $database->prepare("SELECT id, name FROM pages LIMIT 10");
// you can do the following, rather than native PDO $query->execute();


// basic usage
$bool = $database->execute(\PDOStatement $query);

// usage with all arguments
$bool = $database->execute(\PDOStatement $query, bool $throw = true, int $maxTries = 3);


throw (optional)bool

Whether or not to throw exception on query error (default=true)

maxTries (optional)int

Max number of times it will attempt to retry query on error

Return value


True on success, false on failure. Note if you want this, specify $throw=false in your arguments.


Method can throw exceptions on error:

  • \PDOException

$database methods and properties

API reference based on ProcessWire core version 3.0.148

Twitter updates

  • This week we’ve got a couple of really useful API-side improvements to the core in 3.0.151, including predefined image settings and static language translation improvements— More
    21 February 2020
  • New post in the blog about all the fun we had driving around a DDOS attack on our forums, how we got it back under control, and what we learned along the way. Plus PW 3.0.150 dev details and links! More
    7 February 2020
  • New post: ProcessWire core updates (January 31, 2020)— More
    31 January 2020

Latest news

  • ProcessWire Weekly #302
    In the 302nd issue of ProcessWire Weekly we're going to dig into ProcessWire 3.0.151, introduce a new third party module called PrivacyWire, and showcase some interesting ProcessWire highlights from the past week or so. Read on!
    Weekly.pw / 22 February 2020
  • ProcessWire 3.0.151 core updates
    Blog / 21 February 2020
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer