I have a WIP project that has come along just fine, there is just one kink that I cannot seem to work out, creating the table to log everything. I have tried db_query with the export I get from SQL, I have tried db_create_table making everything into arrays and neither have worked. What I have right now is as follows:
$smcFunc['db_create_table']('{db_prefix}[REDACTED]_info',
array(
array(
'name' => 'id',
'type' => 'int',
'size' => 10,
'auto' => true
),
array(
'name' => 'type',
'type' => 'smallint',
'size' => 2,
'default' => '0'
),
array(
'name' => 'points',
'type' => 'tinyint',
'size' => 3,
'default' => '0'
),
array(
'name' => '[REDACTED]_id',
'type' => 'varchar',
'size' => 32
),
array(
'name' => 'member',
'type' => 'mediumint',
'size' => 8,
'default' => 'null',
'null' => true
),
array(
'name' => 'released',
'type' => 'int',
'null' => false
),
array(
'name' => 'caught',
'type' => 'int',
'size' => 10,
'default' => 'null',
'null' => true
)
),
array(
array(
'name' => 'id',
'type' => 'primary',
'columns' => array('id')
)
)
);
Hello:
The code below is from the project I'm working on now, but it should answer all your questions if you take the time to look it over.
I hope this helps.
Wiz
global $smcFunc, $db_prefix;
// New settings for the shop mod
$newSettings = array(
'shopVersion' => '3.0',
'shopDate' => '23th November 2009',
'shopBuild' => '15',
'shopCurrencyPrefix' => '',
'shopCurrencySuffix' => ' credits',
'shopPointsPerTopic' => '10',
'shopPointsPerPost' => '8',
'shopInterest' => '2',
'shopBankEnabled' => '1',
'shopImageWidth' => '100',
'shopImageHeight' => '100',
'shopTradeEnabled' => '1',
'shopItemsPerPage' => '12',
'shopMinDeposit' => '0',
'shopMinWithdraw' => '0',
'shopRegAmount' => '0',
'shopPointsPerWord' => '0',
'shopPointsPerChar' => '0',
'shopPointsLimit' => '0',
'shopFeeWithdraw' => '0',
'shopFeeDeposit' => '0',
'NumberOfShopItemsToDisplay' => '15',
'ToyShopPortrait' => 'The Doctor',
);
// Insert into the database
foreach ($newSettings as $variable => $value)
{
$smcFunc['db_insert']('replace', '{db_prefix}settings',
array(
'variable' => 'string',
'value' => 'string',
),
array(
'variable' => $variable,
'value' => $value,
),
array()
);
}
// Add a column for money
$smcFunc['db_add_column']('{db_prefix}members', array(
'name' => 'money',
'type' => 'decimal',
'default' => '100.00',
));
// Add a column for banked money
$smcFunc['db_add_column']('{db_prefix}members', array(
'name' => 'moneyBank',
'type' => 'decimal',
'default' => '0.00',
));
// Modify Boards
$smcFunc['db_add_column']('{db_prefix}boards', array(
'name' => 'countMoney',
'type' => 'tinyint',
'size' => 1,
'default' => '1',
));
$smcFunc['db_add_column']('{db_prefix}boards', array(
'name' => 'shop_pertopic',
'type' => 'decimal',
'size' => '9,2',
'default' => '0.00',
));
$smcFunc['db_add_column']('{db_prefix}boards', array(
'name' => 'shop_perpost',
'type' => 'decimal',
'size' => '9,2',
'default' => '0.00',
));
$smcFunc['db_add_column']('{db_prefix}boards', array(
'name' => 'shop_bonuses',
'type' => 'tinyint',
'size' => 1,
'default' => '1',
));
// Item table
$smcFunc['db_create_table']('{db_prefix}shop_items',
array(
array(
'name' => 'id',
'type' => 'int',
'size' => 10,
'auto' => true,
),
array(
'name' => 'name',
'type' => 'varchar',
'size' => 50,
),
array(
'name' => 'desc',
'type' => 'text',
),
array(
'name' => 'price',
'type' => 'decimal',
'size' => '8,2',
'default' => '0.00',
),
array(
'name' => 'module',
'type' => 'tinytext',
),
array(
'name' => 'stock',
'type' => 'smallint',
'size' => 6,
),
array(
'name' => 'info1',
'type' => 'text',
'null' => true,
),
array(
'name' => 'info2',
'type' => 'text',
'null' => true,
),
array(
'name' => 'info3',
'type' => 'text',
'null' => true,
),
array(
'name' => 'info4',
'type' => 'text',
'null' => true,
),
array(
'name' => 'input_needed',
'type' => 'tinyint',
'size' => 1,
'default' => 0,
),
array(
'name' => 'can_use_item',
'type' => 'tinyint',
'size' => 1,
'default' => 0,
),
array(
'name' => 'delete_after_use',
'type' => 'tinyint',
'size' => 1,
'default' => 0,
),
array(
'name' => 'image',
'type' => 'tinytext',
'null' => true,
),
array(
'name' => 'category',
'type' => 'smallint',
'size' => 6,
'default' => 0,
),
),
array(
array(
'name' => 'id',
'type' => 'primary',
'columns' => array('id'),
),
),
array(),
'overwrite');
// Inventory table
$smcFunc['db_create_table']('{db_prefix}shop_inventory',
array(
array(
'name' => 'id',
'type' => 'int',
'size' => 10,
'auto' => true,
),
array(
'name' => 'ownerid',
'type' => 'int',
'size' => 10,
),
array(
'name' => 'itemid',
'type' => 'int',
'size' => 10,
),
array(
'name' => 'amtpaid',
'type' => 'decimal',
'size' => '8,2',
'default' => '0.00',
),
array(
'name' => 'trading',
'type' => 'tinyint',
'size' => 1,
),
array(
'name' => 'tradecost',
'type' => 'decimal',
'size' => '8,2',
'default' => '0.00',
),
),
array(
array(
'name' => 'id',
'type' => 'primary',
'columns' => array('id'),
),
),
array(),
'overwrite');
// Category table
$smcFunc['db_create_table']('{db_prefix}shop_categories',
array(
array(
'name' => 'id',
'type' => 'smallint',
'size' => 5,
'auto' => true,
),
array(
'name' => 'name',
'type' => 'varchar',
'size' => 50,
),
array(
'name' => 'count',
'type' => 'int',
'size' => 10,
),
),
array(
array(
'name' => 'id',
'type' => 'primary',
'columns' => array('id'),
),
),
array(),
'overwrite');
// Create a Column called wizard
global $smcFunc;
if (!array_key_exists('db_add_column', $smcFunc))
db_extend('packages');
$column_array = array(
'column1' => array(
'name' => 'wizard',
'type' => 'varchar',
'size' => '800',
'null' => false,
'default' => ''
)
);
foreach ($column_array as $key => $data)
{
$smcFunc['db_add_column']('{db_prefix}members', $data, array(), 'update', 'fatal');
}
// ***** Doctor Who Item Package *****
global $smcFunc;
// Insert Shop Categories
$smcFunc['db_insert']('insert', '{db_prefix}shop_categories', array(
'name' => 'string',
'id' => 'int',
'count' => 'int'
),
// Values
array(
'name' => 'The Doctors',
'id' => '500',
'count' => '11'
));
// Insert shop items
$smcFunc['db_insert']('insert', '{db_prefix}shop_items',
// Fields
array(
'name' => 'string',
'desc' => 'string',
'price' => 'float',
'module' => 'string',
'stock' => 'int',
'image' => 'string',
'info1' => 'int',
'info2' => 'int',
'input_needed' => 'int',
'can_use_item' => 'int',
'delete_after_use' => 'int',
'category' => 'int'
),
// Values
array(
// 1. - 1st Doctor
array(
'name' => '01st Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'Doctor01',
'stock' => 50,
'image' => 'doctor01.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 2. - 2nd Doctor
array(
'name' => '02nd Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'Doctor02',
'stock' => 50,
'image' => 'doctor02.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 3. - 3rd Doctor
array(
'name' => '03rd Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor03',
'stock' => 50,
'image' => 'doctor03.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 4. - 4th Doctor
array(
'name' => '04th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor04',
'stock' => 50,
'image' => 'doctor04.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 5. - 5th Doctor
array(
'name' => '05th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor05',
'stock' => 50,
'image' => 'doctor05.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 6. - 6th Doctor
array(
'name' => '06th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor06',
'stock' => 50,
'image' => 'doctor06.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 7. - 7th Doctor
array(
'name' => '07th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor07',
'stock' => 50,
'image' => 'doctor07.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 8. - 8th Doctor
array(
'name' => '08th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor08',
'stock' => 50,
'image' => 'doctor08.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 9. - 9th Doctor
array(
'name' => '09th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor09',
'stock' => 50,
'image' => 'doctor09.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 10. - 10th Doctor
array(
'name' => '10th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor10',
'stock' => 50,
'image' => 'doctor10.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
// 11. - 11th Doctor
array(
'name' => '11th Doctor',
'desc' => 'Doctor Who',
'price' => 50,
'module' => 'doctor11',
'stock' => 50,
'image' => 'doctor11.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
),
array());
// ***** Dalek Item Package *****
global $smcFunc;
// Insert Shop Categories
$smcFunc['db_insert']('insert', '{db_prefix}shop_categories', array(
'name' => 'string',
'id' => 'int',
'count' => 'int'
),
// Values
array(
'name' => 'The Daleks',
'id' => '501',
'count' => '4'
));
// Insert shop items
$smcFunc['db_insert']('insert', '{db_prefix}shop_items',
// Fields
array(
'name' => 'string',
'desc' => 'string',
'price' => 'float',
'module' => 'string',
'stock' => 'int',
'image' => 'string',
'info1' => 'int',
'info2' => 'int',
'input_needed' => 'int',
'can_use_item' => 'int',
'delete_after_use' => 'int',
'category' => 'int'
),
// Values
array(
// Dalek 1
array(
'name' => 'Dalek 1',
'desc' => 'Doctor Who',
'price' => 100,
'module' => 'dalek1',
'stock' => 50,
'image' => 'Dalek 1.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 501
),
// Dalek 2
array(
'name' => 'Dalek 2',
'desc' => 'Doctor Who',
'price' => 100,
'module' => 'dalek2',
'stock' => 50,
'image' => 'Dalek 2.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 501
),
// Dalek 3
array(
'name' => 'Dalek 3',
'desc' => 'Doctor Who',
'price' => 100,
'module' => 'dalekl3',
'stock' => 50,
'image' => 'Dalek 3.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 501
),
// Dalek 4
array(
'name' => 'Dalek 4',
'desc' => 'Doctor Who',
'price' => 100,
'module' => 'dalek4',
'stock' => 50,
'image' => 'Dalek 4.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 501
),
),
array());