Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 382 Vote(s) - 3.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WHMCS, how can I run code only once

#1
I have create some functions that are hooked on several WHMCS hooks. Some of my functions are require to be a new table in database that I create for my functionality.

What I like to do is to programmatically create the table into Database, but run the code that generate the table only one time and never run that code again.

Is there any way or a good idea on how to do that ?
Reply

#2
In my WHMCS module that I have created, I use the following logic:

if(!mysql_num_rows(mysql_query("SHOW TABLES LIKE 'modulename_%'"))) {

// there are no tables in the database for our module so we need to create them

}

I then use the following to create the database:

$createTable[] = 'CREATE TABLE IF NOT EXISTS `modulename_table` ( `id` int(11) NOT NULL auto_increment, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;';

I have many of these which I then run through a loop:

$createTableCount = 0;
for($s=0,$e=count($createTable); $s<$e; $s++){
$query = mysql_query($createTable[$s]);
if($query)
$createTableCount++;
}

I then add each column to the table:

$alterTable[] = 'ALTER TABLE `modulename_table` ADD `something` int(11) NOT NULL;';

which I also run through a loop - this allows me to add new columns/tables and re-run the installation script and add any columns/tables that don't already exist.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through