Home  >  Article  >  Backend Development  >  Insert operation of PHP PDO database class

Insert operation of PHP PDO database class

WBOY
WBOYOriginal
2016-07-25 08:54:331251browse
  1. //Data insertion

  2. //Prepare SQL statement
  3. $sql = "INSERT INTO `test`(`name`) VALUES (:name)";
  4. //Call the prepare method to prepare to query bbs.it-home.org

  5. $stmt = $pdo->prepare($sql);

  6. //Pass a The array binds values ​​to the named parameters in the preprocessed query and executes SQL

  7. $stmt->execute(array(':name' => '王五'));

  8. //Get the ID value of the last inserted data

  9. echo $pdo->lastInsertId() . '
    ';

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn