function up_3186_3200($_prefix, $_link) { $commands = array(); $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "alerts` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `created` int(10) unsigned NOT NULL DEFAULT '0', `receiver_user_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `receiver_browser_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `event_action_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `text` mediumtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `displayed` tinyint(1) unsigned NOT NULL DEFAULT '0', `accepted` tinyint(1) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "predefined` ADD `invitation_auto` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL AFTER `invitation`"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "predefined` CHANGE `invitation` `invitation_manual` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "predefined` CHANGE `website_push` `website_push_manual` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "predefined` ADD `website_push_auto` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL AFTER `website_push_manual`"; $commands[] = "UPDATE `" . DBManager::RealEscape($_prefix) . "predefined` SET `invitation_auto`=`invitation_manual`"; $commands[] = "UPDATE `" . DBManager::RealEscape($_prefix) . "predefined` SET `website_push_auto`=`website_push_manual`"; $commands[] = "RENAME TABLE `" . DBManager::RealEscape($_prefix) . "rooms` TO `" . DBManager::RealEscape($_prefix) . "chat_rooms`;"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "chat_rooms` ADD `creator` varchar(32 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT ''"; $commands[] = "RENAME TABLE `" . DBManager::RealEscape($_prefix) . "posts` TO `" . DBManager::RealEscape($_prefix) . "chat_posts`;"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "chat_posts` ADD `chat_id` varchar(32 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' AFTER `id` "; $commands[] = "RENAME TABLE `" . DBManager::RealEscape($_prefix) . "res` TO `" . DBManager::RealEscape($_prefix) . "resources`;"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "chats` ADD `group_id` varchar(32 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' AFTER `internal_id`"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "logins` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`user_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`ip` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`time` int(11) unsigned NOT NULL DEFAULT '0', `password` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "chat_requests` ( `id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `created` int(10) unsigned NOT NULL DEFAULT '0', `sender_system_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `sender_group_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `receiver_user_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `receiver_browser_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `event_action_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `text` mediumtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `displayed` tinyint(1) unsigned NOT NULL DEFAULT '0', `accepted` tinyint(1) unsigned NOT NULL DEFAULT '0', `declined` tinyint(1) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "events` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`name` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`created` int(10) unsigned NOT NULL DEFAULT '0', `creator` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `edited` int(10) unsigned NOT NULL DEFAULT '0', `editor` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `pages_visited` int(10) unsigned NOT NULL DEFAULT '0', `time_on_site` int(10) unsigned NOT NULL DEFAULT '0', `max_trigger_amount` int(10) unsigned NOT NULL DEFAULT '0', `trigger_again_after` int(10) unsigned NOT NULL DEFAULT '0', `not_declined` tinyint(1) unsigned NOT NULL DEFAULT '0', `not_accepted` tinyint(1) unsigned NOT NULL DEFAULT '0', `not_in_chat` tinyint(1) unsigned NOT NULL DEFAULT '0', `priority` int(10) unsigned NOT NULL DEFAULT '0', `is_active` tinyint(1) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "event_actions` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `eid` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `type` tinyint(2) unsigned NOT NULL DEFAULT '0', `value` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "event_action_internals` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`created` int(10) unsigned NOT NULL DEFAULT '0',`trigger_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`receiver_user_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "event_action_invitations` ( `id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `action_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `position` varchar(2) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `speed` tinyint(1) NOT NULL DEFAULT '1', `slide` tinyint(1) NOT NULL DEFAULT '1', `margin_left` int(11) NOT NULL DEFAULT '0', `margin_top` int(11) NOT NULL DEFAULT '0', `margin_right` int(11) NOT NULL DEFAULT '0', `margin_bottom` int(11) NOT NULL DEFAULT '0', `style` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `close_on_click` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "event_action_receivers` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `action_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `receiver_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "event_action_senders` ( `id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `pid` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `user_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `group_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `priority` tinyint(2) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "event_action_website_pushs` ( `id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `action_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `target_url` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `ask` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "event_triggers` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `receiver_user_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `receiver_browser_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `action_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `time` int(10) unsigned NOT NULL DEFAULT '0', `triggered` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "event_urls` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `eid` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `url` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `referrer` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `time_on_site` int(10) unsigned NOT NULL DEFAULT '0', `blacklist` tinyint(1) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "website_pushs` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `created` int(10) unsigned NOT NULL DEFAULT '0', `sender_system_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `receiver_user_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `receiver_browser_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `text` mediumtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `ask` tinyint(1) unsigned NOT NULL DEFAULT '0', `target_url` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `displayed` tinyint(1) unsigned NOT NULL DEFAULT '0', `accepted` tinyint(1) unsigned NOT NULL DEFAULT '0', `declined` tinyint(1) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "predefined` ADD `editable` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';"; $commands[] = "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "chats` ADD `area_code` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' AFTER `group_id`;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "profiles` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `edited` int(11) NOT NULL DEFAULT '0', `first_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `last_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `company` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `fax` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `street` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `zip` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `department` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `city` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `country` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `gender` tinyint(1) NOT NULL DEFAULT '0', `languages` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `comments` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `public` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $commands[] = "CREATE TABLE `" . DBManager::RealEscape($_prefix) . "profile_pictures` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `internal_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `time` int(11) NOT NULL DEFAULT '0', `webcam` tinyint(1) NOT NULL DEFAULT '0', `data` mediumtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;"; $allowedecs = array(1050, 1054, 1054, 1054, 1060, 1060, 1060, 1050, 1060, 1050, 1060, 1050, 1060, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1060, 1060, 1050, 1050); foreach ($commands as $key => $command) { $result = $_link->Query(false, $command); if (!$result && DBManager::GetErrorCode() != $allowedecs[$key]) { return DBManager::GetErrorCode() . ": " . DBManager::GetError() . "\r\n\r\nMySQL Query: " . $commands[$key]; } } return true; }
static function LogError($_sql) { Logging::DatabaseLog(time() . " - " . DBManager::GetErrorCode() . ": " . DBManager::GetError() . "\r\n\r\nSQL: " . $_sql . "\r\n"); }
function GetQueryId($_query, $_referrer, $_maxlength = 255, $_self = false) { if (empty($_query)) { $_query = ""; } if (!$_self && $_maxlength != null && strlen($_query) > $_maxlength) { $_query = substr($_query, 0, $_maxlength); } $result = queryDB(false, "INSERT INTO `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "` (`id`, `query`) VALUES (NULL, '" . DBManager::RealEscape($_query) . "');"); if (!$_self && !empty($_query) && !$result && !isnull(DBManager::GetErrorCode()) && DBManager::GetErrorCode() != 1062) { $this->GetQueryId(utf8_encode(urldecode($_query)), $_referrer, $_maxlength, true); } $row = DBManager::FetchArray(queryDB(true, "SELECT `id` FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "` WHERE `query`='" . DBManager::RealEscape($_query) . "';")); return $row["id"]; }
static function CreateTables($id = 0) { if (OperatorRequest::IsAdministrator(true)) { $connection = new DBManager($_POST[POST_INTERN_DATABASE_USER], $_POST[POST_INTERN_DATABASE_PASS], $_POST[POST_INTERN_DATABASE_HOST], "", $_POST[POST_INTERN_DATABASE_PREFIX]); $engine = !empty($_POST["p_db_eng"]) && $_POST["p_db_eng"] == "InnoDB" ? "InnoDB" : "MyISAM"; if (!empty($_POST["p_db_ext"])) { DBManager::$Extension = strtolower($_POST["p_db_ext"]); } if (DBManager::$Extension == "mysql" && !function_exists("mysql_connect")) { Server::$Response->SetStandardResponse($id, base64_encode("PHP MySQL extension is missing (php_mysql.dll)")); return false; } else { if (DBManager::$Extension == "mysqli" && !function_exists("mysqli_connect")) { Server::$Response->SetStandardResponse($id, base64_encode("PHP MySQLi extension is missing (php_mysqli.dll)")); return false; } } $connection->InitConnection(); if (!DBManager::$Provider) { $error = DBManager::GetError(); Server::$Response->SetStandardResponse($id, base64_encode("Can't connect to database. Invalid host or login! (" . DBManager::GetErrorCode() . (!empty($error) ? ": " . $error : "") . ")")); return false; } else { $connection->Query(false, "SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'"); $db_selected = $connection->SelectDatabase(DBManager::RealEscape($_POST[POST_INTERN_DATABASE_NAME])); if (!$db_selected) { if (!empty($_POST[POST_INTERN_DATABASE_CREATE])) { $resultcr = $connection->Query(false, "CREATE DATABASE `" . DBManager::RealEscape($_POST[POST_INTERN_DATABASE_NAME]) . "`"); if (!$resultcr) { Server::$Response->SetStandardResponse($id, base64_encode(DBManager::GetErrorCode() . ": " . DBManager::GetError())); } else { unset($_POST[POST_INTERN_DATABASE_CREATE]); return ServerManager::CreateTables(); } } else { Server::$Response->SetStandardResponse(2, base64_encode(DBManager::GetErrorCode() . ": " . DBManager::GetError())); } } else { $resultvc = $connection->Query(false, "SELECT `version`,`chat_id`,`ticket_id` FROM `" . DBManager::RealEscape($_POST[POST_INTERN_DATABASE_PREFIX]) . DATABASE_INFO . "` ORDER BY `version` DESC LIMIT 1"); if ($rowvc = @DBManager::FetchArray($resultvc)) { if (VERSION != $rowvc["version"] && !empty($rowvc["version"])) { $upres = ServerManager::InitUpdateDatabase($rowvc["version"], $connection, $_POST[POST_INTERN_DATABASE_PREFIX], $engine); if ($upres === true) { Server::$Response->SetStandardResponse(1, base64_encode("")); return true; } } } $resultv = $connection->Query(false, $sql = "SELECT VERSION() as `mysql_version`"); if (!$resultv) { Server::$Response->SetStandardResponse($id, base64_encode(DBManager::GetErrorCode() . ": " . DBManager::GetError() . "\r\n\r\nSQL: " . $sql)); return false; } else { $mrow = @DBManager::FetchArray($resultv); $mversion = explode(".", $mrow["mysql_version"]); if (count($mversion) > 0 && $mversion[0] < MYSQL_NEEDED_MAJOR) { Server::$Response->SetStandardResponse($id, base64_encode("LiveZilla requires MySQL version " . MYSQL_NEEDED_MAJOR . " or greater. The MySQL version installed on your server is " . $mrow["mysql_version"] . ".")); return false; } } $commands = explode("###", str_replace("<!--engine-->", $engine, str_replace("<!--version-->", VERSION, str_replace("<!--prefix-->", $_POST[POST_INTERN_DATABASE_PREFIX], file_get_contents(LIVEZILLA_PATH . "_definitions/dump.lsql"))))); foreach ($commands as $sql) { if (empty($sql)) { continue; } $result = $connection->Query(false, trim($sql)); if (!$result && DBManager::GetErrorCode() != 1050 && DBManager::GetErrorCode() != 1005 && DBManager::GetErrorCode() != 1062) { Server::$Response->SetStandardResponse($id, base64_encode(DBManager::GetErrorCode() . ": " . DBManager::GetError() . "\r\n\r\nSQL: " . $sql)); return false; } } ServerManager::ImportButtons(PATH_IMAGES . "buttons/", $_POST[POST_INTERN_DATABASE_PREFIX], $connection); DBManager::$Connector = $connection; Server::$Response->SetStandardResponse(1, base64_encode("")); return true; } } } return false; }
function testDataBase($_host, $_user, $_pass, $_dbname, $_prefix, $_extension = "", $_intense = false) { global $DB_CONNECTOR; $connection = new DBManager($_user, $_pass, $_host, "", $_prefix); if (!empty($_extension)) { DBManager::$Extension = $_extension; } if (DBManager::$Extension == "mysql" && !function_exists("mysql_connect")) { return "PHP MySQL extension is missing (php_mysql.dll)"; } else { if (DBManager::$Extension == "mysqli" && !function_exists("mysqli_connect")) { return "PHP/MySQLi extension is missing (php_mysqli.dll)"; } } $connection->InitConnection(); $connection->Query(false, "SET NAMES 'utf8'"); if (!DBManager::$Provider) { $error = DBManager::GetError(); return "Can't connect to database. Invalid host or login! (" . DBManager::GetErrorCode() . (!empty($error) ? ": " . $error : "") . ")"; } else { $db_selected = $connection->SelectDatabase(DBManager::RealEscape($_dbname)); if (!$db_selected) { return DBManager::GetErrorCode() . ": " . DBManager::GetError(); } else { $resultv = $connection->Query(false, "SELECT VERSION() as `mysql_version`"); if (!$resultv) { return DBManager::GetErrorCode() . ": " . DBManager::GetError(); } else { $mrow = @DBManager::FetchArray($resultv); $mversion = explode(".", $mrow["mysql_version"]); if (count($mversion) > 0 && $mversion[0] < MYSQL_NEEDED_MAJOR) { return "LiveZilla requires MySQL version " . MYSQL_NEEDED_MAJOR . " or greater. The MySQL version installed on your server is " . $mrow["mysql_version"] . "."; } } $result = $connection->Query(false, "SELECT `version`,`chat_id`,`ticket_id` FROM `" . DBManager::RealEscape($_prefix) . DATABASE_INFO . "` ORDER BY `version` DESC LIMIT 1"); $row = @DBManager::FetchArray($result); $version = $row["version"]; if (!$result || empty($version)) { return "Cannot read the LiveZilla Database version. Please try to recreate the table structure. If you experience this message during installation process, please try to setup a prefix (for example lz_)."; } if ($version != VERSION && defined("SERVERSETUP") && SERVERSETUP) { $upres = initUpdateDatabase($version, $connection, $_prefix); if ($upres !== true) { return "Cannot update database structure from [" . $version . "] to [" . VERSION . "]. Please make sure that the user " . $_user . " has the MySQL permission to ALTER tables in " . $_dbname . ".\r\n\r\nError: " . $upres; } } else { if ($version != VERSION && empty($_GET["iv"])) { return "Invalid database version: " . $version . " (required: " . VERSION . "). Please validate the database in the server administration panel first.\r\n\r\n"; } } $DB_CONNECTOR = $connection; $result = $connection->Query(false, "SELECT * FROM `" . DBManager::RealEscape($_prefix) . DATABASE_OPERATORS . "`"); if (DBManager::GetRowCount($result) == 0) { setManagement($_prefix, false, true); } if ($_intense && empty($_GET["iv"])) { foreach (get_defined_constants() as $constant => $val) { if (substr($constant, 0, 9) == "DATABASE_") { if (!$connection->Query(false, "SELECT * FROM `" . DBManager::RealEscape($_prefix) . $val . "` LIMIT 1;")) { $code = DBManager::GetErrorCode(); $error = DBManager::GetError(); if ($code == 144 || $code == 145 || $code == 1194) { $connection->Query(true, "REPAIR TABLE `" . DBManager::RealEscape($_prefix) . $val . "`;"); $error .= " - (trying to repair ...)"; } return $code . ": " . $error; } } } } return null; } } }
function Query($_log, $_sql, &$_errorCode = -1) { if (DBManager::$Extension == "mysql") { $result = @mysql_query($_sql, DBManager::$Provider); } else { if (DBManager::$Extension == "mysqli") { $result = @mysqli_query(DBManager::$Provider, $_sql); } } $ignore = array("1146", "1045", "2003", "1213", ""); if (!$result && !in_array(DBManager::GetErrorCode(), $ignore)) { $_errorCode = DBManager::GetErrorCode(); if ($_log) { logit(time() . " - " . $_errorCode . ": " . DBManager::GetError() . "\r\n\r\nSQL: " . $_sql . "\r\n", FILE_SQL_ERROR_LOG); } } return $result; }