[英]Inserting data into a junction table
This is my current table design 这是我目前的餐桌设计
I have a many to many relationship. 我有很多对很多的关系。
For example I created / inserted an entry to the musicians table how do I actually pass its primary key (id) that is generated from it and immediately insert it to field musician_id from musician_x_instrument table? 例如,我创建了一个表或将表项插入到了musicians表中,实际上我该如何传递从表生成的主键(id),然后立即将其从artist_x_instrument表中插入到字段musicer_id中?
Assuming you use mysqli, you get if using the insert_id function: 假设您使用mysqli,则可以使用insert_id函数:
$query = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart', 617000)";
$mysqli->query($query);
printf ("New Record has id %d.\n", $mysqli->insert_id);
You then insert this ID in the join table as you would insert any other data into any other table. 然后,您可以将此ID插入联接表中,就像将任何其他数据插入任何其他表一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.