Home >Backend Development >PHP Tutorial >Usage of php pdo insert and pdo insertId

Usage of php pdo insert and pdo insertId

WBOY
WBOYOriginal
2016-07-25 08:54:452569browse
  1. $dbconn = array(

  2. 'dns'=>"mysql:host=localhost;dbname=soa",
  3. 'dbuser'=>'root',
  4. 'dbpwd'=>'123456'
  5. );
  6. try{
  7. $db = new PDO($dbconn['dns'],$dbconn['dbuser'],$dbconn['dbpwd']);
  8. $ db->query("set names utf8");
  9. $update = "update wp_links set link_url = 'www.163.com' where link_id=1";
  10. $insert = "insert into wp_links (link_url,link_name) values ('www.gosoa.com.cn','scofield blog')";
  11. $db->exec($insert);
  12. echo $db->lastInsertId();

  13. {
  14. echo $e->getMessage();
  15. }
Copy code

exec() function is to perform insert update delete operations of. Most of the commonly used select operations use the query function.

The above introduces the usage of php pdo insert and pdo insertId. I hope it will be helpful to everyone.



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