Related Links : Search Engine Optimization | | Search Engine Marketing | Online Marketing | Freelance Programmer| SEO Thailand | SEO Expert | SEO services | PHP Programmer Thailand | SEO Tutorial | What is SEO |

  Home Our SEO Services SEO Expert Consultant Php Programmer Keyword Suggestion Scripts|Articles| Email : sachin {at} jainsachin {dot} com

PHP | Executes a prepared statement | Manual | Tutorial | Help

SEO Services



Website Programming in PHP / MYSQL



SEO Tools




    Friends


      Executes a prepared statement

      PDOStatement->execute

      (PHP 5 >= 5.1.0, PECL pdo:0.1-1.0.3)

      PDOStatement->execute — Executes a prepared statement

      Description

      bool PDOStatement::execute ([ array $input_parameters ] )

      Execute the prepared statement. If the prepared statement included parameter markers, you must either:

      • call PDOStatement::bindParam() to bind PHP variables to the parameter markers: bound variables pass their value as input and receive the output value, if any, of their associated parameter markers

      • 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.

      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.

      Return Values

      Returns TRUE on success or FALSE on failure.

      Examples

      Example #1 Execute a prepared statement with bound variables

      <?php
      /* Execute a prepared statement by binding PHP variables */
      $calories 150;
      $colour 'red';
      $sth $dbh->prepare('SELECT name, colour, calories
          FROM fruit
          WHERE calories < :calories AND colour = :colour'
      );
      $sth->bindParam(':calories'$caloriesPDO::PARAM_INT);
      $sth->bindParam(':colour'$colourPDO::PARAM_STR12);
      $sth->execute();
      ?>

      Example #2 Execute a prepared statement with an array of insert values (named parameters)

      <?php
      /* Execute a prepared statement by passing an array of insert values */
      $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));
      ?>

      Example #3 Execute a prepared statement with an array of insert values (placeholders)

      <?php
      /* Execute a prepared statement by passing an array of insert values */
      $calories 150;
      $colour 'red';
      $sth $dbh->prepare('SELECT name, colour, calories
          FROM fruit
          WHERE calories < ? AND colour = ?'
      );
      $sth->execute(array($calories$colour));
      ?>

      Example #4 Execute a prepared statement with question mark placeholders

      <?php
      /* Execute a prepared statement by binding PHP variables */
      $calories 150;
      $colour 'red';
      $sth $dbh->prepare('SELECT name, colour, calories
          FROM fruit
          WHERE calories < ? AND colour = ?'
      );
      $sth->bindParam(1$caloriesPDO::PARAM_INT);
      $sth->bindParam(2$colourPDO::PARAM_STR12);
      $sth->execute();
      ?>

      SEO Tutorial / Articles





      Php / Mysql Tutorial



      Articles



        Other Topics



        SEO by Jainsachin