PDOStatement::execute
(no version information, might be only in CVS)
PDOStatement::execute --
プリペアドステートメントを実行する
説明
bool
PDOStatement::execute ( [array input_parameters] )
プリペアドステートメントを実行します。もし、プリペアドステートメントが
パラメータマーカを含む場合、次のいずれかを行わなければなりません。
例
例 1. バインド変数を伴うプリペアドステートメントの実行
<?php /* バインド変数を伴うプリペアドステートメントの実行 */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute(); ?>
|
|
例 2. 入力値の配列を伴うプリペアドステートメントの実行
<?php /* 入力値の配列を伴うプリペアドステートメントの実行 */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->execute(array(':calories' => $calories, ':colour' => $colour)); ?>
|
|
例 3. 疑問符プレースホルダを伴うプリペアドステートメントの実行
<?php /* バインド変数を伴うプリペアドステートメントの実行 */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ? AND colour = ?'); $sth->bindParam(1, $calories, PDO::PARAM_INT); $sth->bindParam(2, $colour, PDO::PARAM_STR, 12); $sth->execute(); ?>
|
|
参考
PDO::prepare() |
PDOStatement::bindParam() |
PDOStatement::fetch() |
PDOStatement::fetchAll() |
PDOStatement::fetchColumn() |