db updates, remove init_connection()

This commit is contained in:
Andrew Dolgov 2013-04-17 14:23:35 +04:00
parent 9594791782
commit ba68b6815a
21 changed files with 47 additions and 51 deletions

View File

@ -54,7 +54,7 @@
@session_start(); @session_start();
} }
if (!init_connection($link)) return; if (!init_plugins($link)) return;
$method = strtolower($_REQUEST["op"]); $method = strtolower($_REQUEST["op"]);

View File

@ -49,7 +49,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return; if (!init_plugins($link)) return;
header("Content-Type: text/json; charset=utf-8"); header("Content-Type: text/json; charset=utf-8");

View File

@ -16,6 +16,7 @@ class Db implements IDb {
} }
$this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);
$this->adapter->init();
} }
private function __clone() { private function __clone() {
@ -33,6 +34,10 @@ class Db implements IDb {
return("'$str'"); return("'$str'");
} }
function init() {
//
}
function connect($host, $user, $pass, $db, $port) { function connect($host, $user, $pass, $db, $port) {
//return $this->adapter->connect($host, $user, $pass, $db, $port); //return $this->adapter->connect($host, $user, $pass, $db, $port);
} }

View File

@ -55,5 +55,15 @@ class Db_Mysql implements IDb {
return mysql_affected_rows($this->link); return mysql_affected_rows($this->link);
} }
function init() {
$this->query("SET time_zone = '+0:0'");
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
$this->query("SET NAMES " . MYSQL_CHARSET);
}
return true;
}
} }
?> ?>

View File

@ -69,5 +69,13 @@ class Db_Pgsql implements IDb {
return pg_last_error($this->link); return pg_last_error($this->link);
} }
function init() {
$this->query("set client_encoding = 'UTF-8'");
pg_set_client_encoding("UNICODE");
$this->query("set datestyle = 'ISO, european'");
$this->query("set TIME ZONE 0");
return true;
}
} }
?> ?>

View File

@ -1,6 +1,7 @@
<?php <?php
interface IDb { interface IDb {
function connect($host, $user, $pass, $db, $port); function connect($host, $user, $pass, $db, $port);
function init();
function escape_string($s, $strip_tags = true); function escape_string($s, $strip_tags = true);
function query($query, $die_on_error = true); function query($query, $die_on_error = true);
function fetch_assoc($result); function fetch_assoc($result);

View File

@ -3371,41 +3371,13 @@
return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0; return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
} }
function init_connection_only($link) { function init_plugins($link) {
if ($link) { global $pluginhost;
if (DB_TYPE == "pgsql") {
pg_query($link, "set client_encoding = 'UTF-8'");
pg_set_client_encoding("UNICODE");
pg_query($link, "set datestyle = 'ISO, european'");
pg_query($link, "set TIME ZONE 0");
} else {
db_query($link, "SET time_zone = '+0:0'");
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { $pluginhost = new PluginHost($link);
db_query($link, "SET NAMES " . MYSQL_CHARSET); $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
}
}
return true; return true;
}
return false;
}
function init_connection($link) {
if ($link) {
init_connection_only($link);
global $pluginhost;
$pluginhost = new PluginHost($link);
$pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
return true;
} else {
print "Unable to connect to database:" . db_last_error();
return false;
}
} }
function format_tags_string($tags, $id) { function format_tags_string($tags, $id) {

View File

@ -31,7 +31,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return; if (!init_plugins($link)) return;
global $pluginhost; global $pluginhost;

View File

@ -11,7 +11,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return; if (!init_plugins($link)) return;
$op = $_REQUEST['op']; $op = $_REQUEST['op'];

View File

@ -18,7 +18,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link); init_plugins($link);
login_sequence($link, true); login_sequence($link, true);

View File

@ -23,7 +23,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link); init_plugins($link);
if (!$_SESSION["uid"]) return; if (!$_SESSION["uid"]) return;

View File

@ -18,7 +18,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link); init_plugins($link);
login_sequence($link, true); login_sequence($link, true);

View File

@ -18,7 +18,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link); init_plugins($link);
login_sequence($link, true); login_sequence($link, true);

View File

@ -18,7 +18,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link); init_plugins($link);
login_sequence($link, true); login_sequence($link, true);

View File

@ -18,7 +18,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link); init_plugins($link);
login_sequence($link, true); login_sequence($link, true);
?> ?>

View File

@ -20,7 +20,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link); init_plugins($link);
login_sequence($link, true); login_sequence($link, true);
?> ?>

View File

@ -21,7 +21,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return; if (!init_plugins($link)) return;
login_sequence($link); login_sequence($link);

View File

@ -30,7 +30,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return; if (!init_plugins($link)) return;
if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) { if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
ob_start("ob_gzhandler"); ob_start("ob_gzhandler");

View File

@ -19,7 +19,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return; if (!init_plugins($link)) return;
if ($_REQUEST["format"] == "feed") { if ($_REQUEST["format"] == "feed") {
header("Content-Type: text/xml"); header("Content-Type: text/xml");

View File

@ -21,7 +21,7 @@
// Create a database connection. // Create a database connection.
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link); init_plugins($link);
$longopts = array("feeds", $longopts = array("feeds",
"feedbrowser", "feedbrowser",

View File

@ -177,7 +177,7 @@
// It is unnecessary to start the fork loop if database is not ok. // It is unnecessary to start the fork loop if database is not ok.
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) die("Can't initialize db connection.\n"); if (!init_plugins($link)) die("Can't initialize db connection.\n");
$schema_version = get_schema_version($link); $schema_version = get_schema_version($link);
@ -203,7 +203,7 @@
/* Check if schema version changed */ /* Check if schema version changed */
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) die("Can't initialize db connection.\n"); if (!init_plugins($link)) die("Can't initialize db connection.\n");
$test_schema_version = get_schema_version($link); $test_schema_version = get_schema_version($link);
db_close($link); db_close($link);
@ -255,7 +255,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return; if (!init_plugins($link)) return;
// We disable stamp file, since it is of no use in a multiprocess update. // We disable stamp file, since it is of no use in a multiprocess update.
// not really, tho for the time being -fox // not really, tho for the time being -fox