General Community > Scripting Help
myseql Database Field - How to add a field in?
Arantor:
So take a look at packages that use it. There are literally dozens of mods that add columns in the DB.
The Wizard:
Good idea
Arantor:
It's how I learned how to do it...
The Wizard:
Hey Marvin (Arantor) take a look at this and see if I got it?
--- Quote ---if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
// Hmm... no SSI.php and no SMF?
elseif (!defined('SMF'))
die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
$smcFunc['db_add_column'](
'{db_prefix}members',
array(
'name' => 'shop_Dog',
'type' => 'text',
'null' => false
)
);
//Add the item
$smcFunc['db_insert']($topicinfo['new_from'] == 0 ? 'ignore' : 'replace',
'{db_prefix}shop_items',
array(
'name' => 'Dog Image',
'desc' => 'Show an image next to your posts',
'price' => '100.00',
'module' => 'Dog',
'Stock' => '50',
'input_needed' => '1',
'can_use_item' => '1'
);
--- End quote ---
Arantor:
Hmm.
--- Code: ---if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
// Hmm... no SSI.php and no SMF?
elseif (!defined('SMF'))
die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
$smcFunc['db_add_column'](
'{db_prefix}members',
array(
'name' => 'shop_Dog',
'type' => 'text',
'null' => false
)
);
$smcFunc['db_insert']($topicinfo['new_from'] == 0 ? 'ignore' : 'replace',
'{db_prefix}shop_items',
array(
'name' => 'string-255', 'desc' => 'string-65534', 'price' => 'string-255', 'module' => 'string-255', 'Stock' => 'int', 'input_needed' => 'int', 'can_use_item' => 'int',
),
array(
'name' => 'Dog Image',
'desc' => 'Show an image next to your posts',
'price' => '100.00',
'module' => 'Dog',
'Stock' => '50',
'input_needed' => '1',
'can_use_item' => '1'
)
);
--- End code ---
A lot of that insert query is pure guesswork, you have to indicate what columns you're sending through and what data types they're supposed to be (just like it is documented, and as per the example in said thread)
The db add column query looks OK, but the real test is if it actually works. If it works and there's no errors, then it's right.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version