教您如何实现MySQL多表插入

MySQL多表插入的实现方法并不复杂,下面就对MySQL多表插入的实现过程作详尽的阐述,如果您对MySQL多表插入方面感兴趣的话,不妨一看。

MySQL多表插入:

 
 
 
  1. $conn = mysql_connect("localhost","charles","charles");  
  2. mysql_select_db("test");  
  3. $query = "INSERT INTO contact(user_name,nom, prenom, mail, passcode) values('sa','se','sf', 'safd@p.com', '123')";  
  4. $result = mysql_query($query) or die("insert contact failed:".mysql_error());  
  5. $lastid = mysql_insert_id(); //得到上一个 插入的id值   
  6. echo "last insert id :".$lastid."
    ";  
  7. $query2 = "INSERT INTO contactdroit(contact_id, droit_id) values('$lastid','11')";  
  8. echo $query2."
    ";  
  9. $result2 = mysql_query($query2) or die("insert contactdroit failed: ".mysql_error());  
  10. if(isset($result) && isset($result2)){  
  11. echo "Good Insertion
    ";  
  12. echo $lastid;  
  13. }  
  14. ?> 

需注意的是:

The mysql_insert_id() function returns the AUTO_INCREMENT ID generated from the previous INSERT operation.
mysql_insert_id()函数的作用是:取得上一步 INSERT 操作产生的 ID。

This function returns 0 if the previous operation does not generate an AUTO_INCREMENT ID, or FALSE on MySQL connection failure.
如果先前的操作不产生一个自动增加的ID[AUTO_INCREMENT ID],那么,函数返回0;如果MySQL连接失败,将返回False。
 

 

 

【编辑推荐】

Mysql临时表的用法

拆表用的MySQL存储过程

深入探讨MySQL锁机制

详解MySQL数据表类型

MySQL添加字段和删除字段


本文题目:教您如何实现MySQL多表插入
当前路径:http://gydahua.com/article/ccsedhe.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流