Insert operation of PHP PDO database class

WBOY
Release: 2016-07-25 08:54:33
Original
1283 people have browsed it
  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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!