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

Pdo::reset

Forget the query being built

Description​

public self Pdo::reset()

Forgets everything set for the next query (table, items, conditions, joins, order, limit ...), turns the reset after execute back on (see unsetInitQueryFlag) and re-enables the automatic queries unless disabledRegularUseQuery was called. The result and the last query are kept.

execute() already does this after a successful query. A query that throws keeps its state, so call reset() after catching a QueryException when you reuse the instance. Fegg\Model does this by itself.

Example​

Controller
use Fegg\Database\QueryException;

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

try {
$db->setWhere('no_such_column = ?', 1)->select('cms_news')->execute();
} catch (QueryException $e) {
$db->reset();
}

$rows = $db->select('cms_news')->execute()->all();