Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 894 Bytes

queries.md

File metadata and controls

53 lines (37 loc) · 894 Bytes

Querying

Execute Queries

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();

Bind Values

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();