PHP MySQL外键自动插入 [英] PHP MySQL foreign-key auto insert

查看:62
本文介绍了PHP MySQL外键自动插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我想做的是,当我的网站用户在我们的注册页面上创建一个新帐户时,我想要User表(基本信息表,电子邮件,密码等)插入到个人资料"表的新行中(有关我的更多描述性信息,显示名称等)

So basically what I am trying to do is when a user of my site creates a new account on our register page, I'd like the primary key from the newly created row on the User table (basic info table, email, password, etc.) to be inserted into a new row on the Profile table (more descriptive info, about me, display name, etc.)

我想用PHP做到这一点,任何帮助将不胜感激.

I'd like to do this in PHP and any help would be appreciated.

推荐答案

如果不是真的需要在php中进行",则可以使用MySQL的内置Trigger机制来进行此更新.

If doing it "in php" isn't really a requirement, then you can use MySQL's built in Trigger mechanism to do this update.

触发器在事件(插入,更新,删除)之后或之前导致某些事情发生

Triggers cause something to happen AFTER or BEFORE an event(INSERT, UPDATE,DELETE)

所以您的触发条件是:

CREATE TRIGGER thistrigger AFTER INSERT
ON User FOR EACH ROW
UPDATE PROFILE SET "whatever"

关于触发器: http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

这篇关于PHP MySQL外键自动插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆