Robust
Well-known member
So, I installed the add-on but it didn't alter the tables, so I'm trying to uninstall it and made some changes for it to work hopefully. It's giving an error now
I might be overlooking something, but I don't see what's wrong.
Code:
Mysqli prepare error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bestanswer' at line 1
Zend_Db_Statement_Mysqli->_prepare() in /Applications/MAMP/htdocs/xenforo/library/Zend/Db/Statement.php at line 115
Zend_Db_Statement->__construct() in /Applications/MAMP/htdocs/xenforo/library/Zend/Db/Adapter/Mysqli.php at line 381
Zend_Db_Adapter_Mysqli->prepare() in /Applications/MAMP/htdocs/xenforo/library/Zend/Db/Adapter/Abstract.php at line 478
Zend_Db_Adapter_Abstract->query() in /Applications/MAMP/htdocs/xenforo/library/Zend/Db/Adapter/Abstract.php at line 825
Zend_Db_Adapter_Abstract->fetchOne() in /Applications/MAMP/htdocs/xenforo/library/BestAnswer/Installer.php at line 57
BestAnswer_Installer::uninstall()
call_user_func() in /Applications/MAMP/htdocs/xenforo/library/XenForo/DataWriter/AddOn.php at line 200
XenForo_DataWriter_AddOn->_postDelete() in /Applications/MAMP/htdocs/xenforo/library/XenForo/DataWriter.php at line 1779
XenForo_DataWriter->delete() in /Applications/MAMP/htdocs/xenforo/library/XenForo/ControllerAdmin/AddOn.php at line 122
XenForo_ControllerAdmin_AddOn->actionDelete() in /Applications/MAMP/htdocs/xenforo/library/XenForo/FrontController.php at line 347
XenForo_FrontController->dispatch() in /Applications/MAMP/htdocs/xenforo/library/XenForo/FrontController.php at line 134
XenForo_FrontController->run() in /Applications/MAMP/htdocs/xenforo/admin.php at line 13
PHP:
<?php
class BestAnswer_Installer
{
protected static $_alters = array(
array(
'checkColumnExists' => 'SHOW COLUMNS FROM `xf_thread` LIKE bestanswer',
'install' => 'ALTER TABLE `xf_thread` ADD COLUMN bestanswer int(10) unsigned',
'uninstall' => 'ALTER TABLE `xf_thread` DROP COLUMN bestanswer'
),
array(
'checkColumnExists' => 'SHOW COLUMNS FROM `xf_user` LIKE bestanswers',
'install' => 'ALTER TABLE `xf_user` ADD COLUMN bestanswers int(10) UNSIGNED NOT NULL DEFAULT 0',
'uninstall' => 'ALTER TABLE `xf_user` DROP COLUMN bestanswers'
)
);
public static function install()
{
$db = XenForo_Application::getDb();
foreach(self::$_alters as $alter)
{
$checkColumnExists = $db->fetchOne($alter['checkColumnExists']);
if(empty($checkColumnExists))
{
$db->query($alter['install']);
}
}
foreach(self::$_tables as $table)
{
$db->query($table['install']);
}
}
public static function uninstall()
{
$db = XenForo_Application::getDb();
foreach(self::$_alters as $alter)
{
$checkColumnExists = $db->fetchOne($alter['checkColumnExists']);
if(!empty($checkColumnExists))
{
$db->query($alter['uninstall']);
}
}
foreach(self::$_tables as $table)
{
$db->query($table['uninstall']);
}
}
}
I might be overlooking something, but I don't see what's wrong.