MyBB Community Forums

Full Version: alter table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how can i include this in a plugin:
ALTER TABLE `mybb_userfields` ADD `fid5` TEXT NOT NULL

i saw some plugins calling the database itself and then executing the command.

how can i do it like this so that MyBB executes the command:
$db->

I am really n00b
thanks a lot Smile
so, i should do this:
$db->query(ALTER TABLE `mybb_userfields` ADD `fid5` TEXT NOT NULL)

How can i remove the prefix from the code so that mybb determines it?


$db->query(ALTER TABLE ".TABLE_PREFIX."userfields ADD `fid5` TEXT NOT NULL)

I don't know if thats correct but .TABLE_PREFIX. grabs it from Mybb.
In 1.4.13 at least the .TABLE_PREFIX. is not neccessary, so this would work:

$db->query(ALTER TABLE `userfields` ADD `fid5` TEXT NOT NULL)
Add quotes around the query otherwise you should expect an error. (and switch to write_query)

(2010-08-19, 12:12 PM)mark-in-dallas Wrote: [ -> ]In 1.4.13 at least the .TABLE_PREFIX. is not neccessary, so this would work:

$db->query(ALTER TABLE `userfields` ADD `fid5` TEXT NOT NULL)
You're wrong. You'll need to add TABLE_PREFIX there because MyBB does not add it to full queries (obviously), only in functions like update_query and delete_query
Pirata, I haven't looked at the differences between query and write_query yet, I suppose I should update my plugins to all use write_query, yes?
(2010-08-19, 06:28 PM)Dylan M. Wrote: [ -> ]Pirata, I haven't looked at the differences between query and write_query yet, I suppose I should update my plugins to all use write_query, yes?

write_query executes the query on the slave database ($db->write_link) in case you have a multi-server database setup.
Edit:
So yeah editing your would probably good but it's not a great problem Toungue
Well, since I'm updating my plugins for 1.6 compatibility anyways... Wink

Though, in point of fact I think I only have 1 plugin that uses $db->query right now.