如何将多个ID插入到不同的mysql表中?
您好,如何使用此 mysql 语句将与使用此语句创建的帐户相同的 ID 插入到名为“布局”的表中?
$q = $dbc -> prepare("INSERT INTO accounts (email, password, salt, username, gender, loginIP, shrapnel, joined) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$q -> execute(array($_POST['email'], hash('sha512', 'jooosjdsakjdsn' . $_POST['password'] . md5($random)), md5($random), $_POST['username'], $_POST['gender'], $_SERVER['REMOTE_ADDR'], $random, date('Y-m-d : H:i:s')));
可以加入吗? ID是accounts表中的一个自增字段。
Hi how can I insert the same ID as the account being created with this statement into a table which is called layouts using this mysql statement?
$q = $dbc -> prepare("INSERT INTO accounts (email, password, salt, username, gender, loginIP, shrapnel, joined) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$q -> execute(array($_POST['email'], hash('sha512', 'jooosjdsakjdsn' . $_POST['password'] . md5($random)), md5($random), $_POST['username'], $_POST['gender'], $_SERVER['REMOTE_ADDR'], $random, date('Y-m-d : H:i:s')));
Is it possible with a join? The ID is an auto increment field in the table accounts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
之后您可以尝试在另一个查询中立即使用
LAST_INSERT_ID()
。You could try using
LAST_INSERT_ID()
in another query immediately afterwards.你必须像这样在脚本中添加一些sql
插入布局(accountsid,.......)VALUES(LAST_INSERT_ID(),....)。
注意:如果帐户表也有一个标识列并且您多次插入其中,则必须将主表的 LAST_INSERT_ID() 保留到单独的变量中,否则从第二次插入帐户表开始使用 LAST_INSERT_ID() 函数将返回账户表的 ID
you will have to add some sql to your script like this
insert into layouts(accountsid,.......) VALUES(LAST_INSERT_ID(), ....).
Note: if the accounts table also has an identity column and you insert into it multiple times than you have to keep the LAST_INSERT_ID() for the master table into a separate variable otherwise starting with the second insert into the accounts table the LAST_INSERT_ID() function will return the IDs of the accounts table