Execute a SQL statement and get a statement object:
$statement = $connection->query($query);
$rows = $statement->fetchAll();
Execute a SQL statement and get the number of affected rows:
$rowCount = $connection->exec($query);
Prepare a statement before execution:
$statement = $connection->prepare($query);
$statement->execute();
$rows = $statement->fetchAll();
Using the query
method:
$statement = $connection->query($query, $bind);
Using the prepare
method:
$statement = $connection->prepare($query);
$statement->execute($bind);
Example:
use Foundry\Parameter;
$query = $connection
->select()
->from('accounts')
->where('name', '=', new Parameter('name'));
$statement = $connection->query($query, [':name' => $name]);
$rows = $statement->fetchAll();