本文整理汇总了PHP中DBManager::InitConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP DBManager::InitConnection方法的具体用法?PHP DBManager::InitConnection怎么用?PHP DBManager::InitConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBManager
的用法示例。
在下文中一共展示了DBManager::InitConnection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initDataProvider
function initDataProvider($connection = false)
{
global $CONFIG, $DB_CONNECTOR, $CM;
if (!empty($CONFIG["gl_datprov"])) {
if (!defined("DB_PREFIX")) {
define("DB_PREFIX", $CONFIG["gl_db_prefix"]);
}
$DB_CONNECTOR = new DBManager($CONFIG["gl_db_user"], $CONFIG["gl_db_pass"], $CONFIG["gl_db_host"], $CONFIG["gl_db_name"], $CONFIG["gl_db_prefix"]);
if (!empty($CONFIG["gl_db_ext"])) {
DBManager::$Extension = $CONFIG["gl_db_ext"];
}
if ($DB_CONNECTOR->InitConnection()) {
$connection = true;
}
}
if (!defined("DB_CONNECTION")) {
define("DB_CONNECTION", $connection);
}
if ($connection) {
loadDatabaseConfig(false, $CONFIG["gl_db_prefix"]);
if (!isset($CONFIG["gl_caen"])) {
$CONFIG["gl_caen"] = 1;
}
if (!isServerSetup() && !is("IN_API") && CacheManager::CachingAvailable($CONFIG["gl_caen"]) !== false) {
$gttl = min($CONFIG["poll_frequency_clients"], $CONFIG["poll_frequency_tracking"]) * 2;
$sttl = !empty($CONFIG["gl_st_upin"]) ? $CONFIG["gl_st_upin"] : 3600;
$CM = new CacheManager(md5(SUBSITEHOST . $CONFIG["gl_lzid"] . $CONFIG["gl_db_prefix"] . $CONFIG["gl_db_pass"] . $CONFIG["gl_db_user"] . $CONFIG["gl_db_name"]), $gttl, array(111 => array("VISITOR", 512), 112 => array("EVENTS", 128), 113 => array("INTERNAL", 256, $gttl * 2), 114 => array("GROUPS", 256, $gttl * 2), 115 => array("FILTERS", 128, $gttl * 2), 116 => array("DBCNF", 128, $gttl * 2), 117 => array("STATS", 1, $sttl), 118 => array("DUT", 1)));
$CM->Read();
}
loadDatabaseConfig(true, $CONFIG["gl_db_prefix"]);
}
return $connection;
}
示例2: CreateTables
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;
}
示例3: testDataBase
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;
}
}
}