YouTip LogoYouTip

Pdostatement Execute

# PDOStatement::execute [![Image 3: PHP PDO Reference](#)PHP PDO Reference](#) PDOStatement::execute β€” Executes a prepared statement (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0) * * * ## Description ### Syntax bool PDOStatement::execute ([ array $input_parameters ] ) Executes a prepared statement. If the prepared statement contains parameter markers, you must use one of the following methods: * Call [PDOStatement::bindParam()](#) to bind PHP variables to the parameter markers: bind the variables by their corresponding parameter markers, if any, to pass input values and retrieve output values. * Or pass an array of input-only parameter values. * * * ## Parameters **input_parameters** An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as PDO::PARAM_STR. You cannot bind multiple values to a single parameter; for example, you cannot bind two values to a single named parameter in an IN() clause. The number of bound values cannot exceed the specified number. If there are more keys in the input_parameters array than the number of parameters specified in the prepared SQL statement via PDO::prepare(), the statement will fail and an error is emitted. * * * ## Return Value Returns TRUE on success or FALSE on failure. * * * ## Examples ### Executing a prepared statement with bound variables prepare('SELECT name, colour, calories FROM fruit WHERE calories bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute();?> ### Executing a prepared statement with an array of insert values (named parameters) prepare('SELECT name, colour, calories FROM fruit WHERE calories execute(array(':calories' => $calories, ':colour' => $colour));?> ### Executing a prepared statement with an array of insert values (placeholders) prepare('SELECT name, colour, calories FROM fruit WHERE calories execute(array($calories, $colour));?> ### Executing a prepared statement with question mark placeholders prepare('SELECT name, colour, calories FROM fruit WHERE calories bindParam(1, $calories, PDO::PARAM_INT); $sth->bindParam(2, $colour, PDO::PARAM_STR, 12); $sth->execute();?> ### Executing a prepared statement with an IN clause using an array prepare('SELECT name, colour, calories FROM fruit WHERE calories IN (' . $place_holders . ')'); $sth->execute($params);?>
← Pdostatement FetchPdostatement Errorinfo β†’