Now here's a question where the drupal users who know what they're talking about may just tell me not to be daft!

I'm planning on using ModernBill, which gives me the option of running MySQL code each time it sets up a new user (and separate code if it suspends them, and also if it deletes them).

How can I use this to add new users to a drupal installation?

I think I would find it easy enough to add them into the users table, the difficult part is to also increment the counter in the other table that keeps a track of the last allocated userid.

Does anyone have any suggestions of how to do this in just MySQL without using any PHP? Or is this impossible?

Thanks
Steve

Comments

keithmcd’s picture

You should be able to use the following sql statements

To insert the user into the users table:
INSERT INTO users (uid, name, pass, mail, mode, mode, sort, threshold, theme, signature, created, changed, status, timezone, language, picture, init, data) VALUES ((select max(uid)+1 from users), username, password, email, 0, 0, 0, themename, signature, createddefaultto0, changeddefaultto0, statusdefaultto0, , language, picture, init, data);
UPDATE sequences SET users_uid = (select users_uid+1 from sequences);
UPDATE sequences SET contact_category_uid = (select contact_category_uid+1 from sequences);

Of course, you'll have to look at your db to adjust the code accordingly, but that should do the trick. in the sequences table, those two fields i put up there have a prefix of "drupal_" in my db because I have the prefix option set to "drupal_" to distinguish drupal data from other data. All my tables have the same prefix also.

steveparks’s picture

Thanks very much for your help Keith
Steve

===
Steve Parks
Convivio - a digital services agency

http://weareconvivio.com