I want to create some external mysql tables for a phpscript I have made, when I activate new users. I just wonder where I can add my php code that creates the tables

Comments

london3’s picture

Goto http://drupaldocs.org/
Search for: hook_user

This is an example implementation from AstBill
The module name is astpbx. the name of your function have to be
module_name_user($type, &$edit, &$user, $category = NULL)

/**
* Implementation of hook_user().
*/
function astpbx_user($type, &$edit, &$user, $category = NULL) {
global $db_prefix;
// global $active_db;
// $result = mysql_query($query, $active_db);

switch ($type) {
/* case 'load':
return profile_load_profile($user);
case 'register':
return profile_form_profile($edit, $user, $category);
case 'update': */
case 'insert':
$sql = db_query ("CALL astCreateAccount(@a,$user->uid,'IAX')");
$sql2 = db_query("select @a accountcode");
$result = db_fetch_object($sql2);

// drupal_set_message(t('New Account Created: '. $result->accountcode));
astpbx_sendemail("ASTARREG", $user->mail, $result->accountcode);
// $sql = db_query ("insert into test (subject) values ('Drupal $db_prefix $user->uid')");
// $sql = db_query ("insert into test (subject) values ('$item->id')");

/* $sql = db_query ("select brand FROM astuser WHERE uid='%s'", $user->uid); */
/* $sqlget = db_fetch_object($sql); */

/* return profile_save_profile($edit, $user, $category);
case 'view':
return profile_view_profile($user);
case 'form':
return profile_form_profile($edit, $user, $category);
case 'validate':
return profile_validate_profile($edit, $category);
case 'categories':
return profile_categories(); */

}
}

Are Casilla
http://astartelecom.com - Independent Telecoms Broker. Use our VOIP. One World, One Number One Pabx. Experts in Asterisk
http://astbill.com - Billing, Routing and Management software for Asterisk and MySQL. Running on Drupal.
AstBill DEMO: http://demo.astbill.com

ultraBoy’s picture

If you really need to create TABLES (and not RECORDS in tables), you shouldn't create any php code! 'Cause php code is used when you need something to be done repeatedly, and TABLES are created only once. :-0

Tables you can create for example, with phpMyAdmin script.

skatun’s picture

Exactly were can I include my php function mysql($userId) which generate all the tables I need for that user and insert values to it. I want to load this function when I activate a new user.

The code wi look something like this:
include 'mysql.php';

global $user;
$userId = $user->uid;
mysql($userId);

london3’s picture

You have to make a Drupal module.

If your module name is skatun.module

Please put the following function in the module

/**
* Implementation of hook_user().
*/
function skatun_user($type, &$edit, &$user, $category = NULL) {

{

Visit Admininstration/mudules and activate your module.
Next time you create a new user your function will be activated.

You can find out how to create modules in the Drupal Handbook.

Are Casilla
http://astartelecom.com - Independent VOIP Telecoms Broker. Consulting in Asterisk and Drupal
http://astbill.com - Billing, Routing and Management software for Asterisk and MySQL. Running on Drupal
AstBill DEMO: http://demo.astbill.com