PDA

View Full Version : vB Save() mysql_insert_id ?


JamesTalbot
02-18-2008, 05:18 PM
Hey,

I am trying to alter my newly upgraded vBulletin Forum register.php file.

All i want to do is insert the userid from that registered person and insert it into another table.

In vB2 this was very easy. I am unsure how to do this in vB3 though. I have looked at vBulletin Data Documentation but didnt see anything relevant to this issue.

Can anyone help me?

Thanks in Advance.

James

cheesegrits
02-18-2008, 07:25 PM
Don't edit the register.php file. Use a plugin on the register_addmember_complete hook, where $vbulletin->userinfo['userid'] will be the new userid.

-- hugh

Eikinskjaldi
02-18-2008, 08:28 PM
or use a trigger.

Opserty
02-18-2008, 08:53 PM
or use a trigger.
trigger? :confused:

P.S. the id value is normally returned when the save() function is execute so...

$somevar = $userdm->save()

// $somevar is the userid

Obviously it won't be $somevar but it maybe be another variable.

Lynne
02-18-2008, 10:09 PM
Don't edit the register.php file. Use a plugin on the register_addmember_complete hook, where $vbulletin->userinfo['userid'] will be the new userid.

-- hugh
This is exactly what I do for my tracker. I have a separate table for registration to the tracker that I populate with the userid and username at the time of registration. I use the register_addmember_complete hook and simply put a query in there:
$db->query_write("INSERT INTO mytable (all variables) VALUES
(variable contents)
");

JamesTalbot
02-19-2008, 11:04 AM
Sorry, have you got a link for more info on these hooks you are referring to?

EDIT - I have found the hook you are referring to. I will test my code and see if it works.

Thanks.

--------------- Added 1203427548 at 1203427548 ---------------

Thanks that worked great!

:)

James

cheesegrits
02-19-2008, 03:56 PM
trigger? :confused:


As of MySQL 5.02, you can add 'triggers' to tables. So you can specify things like "when data is inserted into table A, do such-and-such to table B". See:

http://dev.mysql.com/doc/refman/5.0/en/triggers.html

The advantage of this approach is that you don't have to write any PHP code, it just happens automagically within MySQL. The disadvantage is that ... well, you don't have any PHP code and it happens automagically within MySQL. So you can't add any data which can't be derived from a select on existing MySQL data, and you can't handle errors gracefully. And of course it's MySQL version specific.

If all you are doing is literally inserting data already present in your table(s) into another table, triggers are a useful shortcut.

-- hugh

Coders Shack
02-19-2008, 05:22 PM
wow thats f***in sweet! Thx for pointing that out, too bad the company i work at still uses PHP 4 ><.

Adrian Schneider
02-19-2008, 05:46 PM
MySQL... not PHP. ;)

Dismounted
02-20-2008, 05:48 AM
Still, most servers have MySQL 4.x installed :p.