简体   繁体   English

如何添加自动递增到php中另一列的主键值?

[英]how can i add primary key value which is auto incremented to another column in php?

I have a tree and I want to I have a table which has an id also, I want to use this id by adding to another column. 我有一棵树,我想有一个也有ID的表,我想通过添加到另一列来使用此ID。

clearly, I want to add id column'value to parent_root column. 显然,我想将id列的值添加到parent_root列。

   sql = "INSERT INTO agac_menu (id,isim,aciklama,parent_id,parent_root,yetki,sira,tip,created)
        VALUES (NULL,'".$isim."','".$aciklama."','".$parent_id."','".$parent_root."','".$yetki."','".$sira."','".$tip."','".date('Y-m-d H:i:s')."')";

如果是MySQL(是的,我知道它更通用),则可以使用触发器: MySQL触发器last_insert_id()

You can't do this in the same query--the auto incremented id doesn't exist until the record is inserted. 您不能在同一查询中执行此操作-自动增量ID在插入记录之前不存在。 After your query runs in php, grab the last insert id and run an update query. 在php中运行查询后,获取最后一个插入ID并运行更新查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在非主键列上添加自动增量,但它们仍然是我要设置为主键的另一列 - how to add auto-increments on non primary key column, but their is still another column which i want to set as primary key 当主键自动递增时,如何在SQL中自动递增另一列? - How to auto increment another column in sql when the primary key is auto incremented? 获取自动增量主键插入另一个表的线程安全方法(以便以后可以将它们联接) - Thread safe way to get auto incremented primary key inserted into another table (so they can be joined later) 我如何在控制器内的 Laravel 的不同表中获取自动递增 id 的值作为外键 - how can i get the value of an an auto incremented id as a foreign key in a different table in Laravel inside a controller 如何使用SQL'Default'关键字为自动递增的主键进行PHP插入 - How to do PHP insert using SQL 'Default' keyword for auto incremented primary key 如何从具有主键自动增量的表中向具有外键的表中插入数据? - How can I insert data to a table which has a foreign key, from a table which has a primary key auto-increment? 如何从PHP中具有相同键的另一个数组向数组的键添加值? - How can I add a value to an array's key from another array with the same key in PHP? 如何将行自动添加到表中,这会影响主键 - How Can i add row to my table that is auto increment that will affect my primary key 如何在新的html表单中使用自动递增的MySQL密钥? - How can I use an auto-incremented MySQL key in a new html form? 当主键“ Submission_ID”和“ TimeEntered”自动递增时如何设置表数据 - How to SET table data when the Primary Key “Submission_ID” and “TimeEntered” are auto incremented
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM