メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Pdo::execute

Execute built query

Description​

public self Pdo::execute()

Builds the query (when a build method such as select was called) or takes the one set with setQuery, and runs it. SELECT and PRAGMA queries run on a slave and their rows are read with all or one; other queries run on the master. Inside a transaction every query runs on the transaction's connection. Afterwards the query being built is forgotten (see unsetInitQueryFlag).

Throws Fegg\Database\QueryException when the connection or the query fails. Its message ends with the SQL with the values filled in.

Example​

Controller
$db = new \Fegg\Database\Pdo();

$rows = $db->setWhere('category = ?', 2)->select('cms_news')->execute()->all();

$db->setValues(array('title' => 'Sample'))->insert('cms_news')->execute();
$id = $db->getLastIndexId();