summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend.php10
-rw-r--r--errors.php2
-rw-r--r--functions.php16
-rw-r--r--mobile/tt-rss.php10
-rw-r--r--mysql_convert_unicode.php12
-rw-r--r--opml.php11
-rw-r--r--update.php11
-rw-r--r--update_daemon.php12
-rw-r--r--update_daemon2.php11
-rw-r--r--update_daemon_loop.php10
-rw-r--r--update_feeds.php10
-rw-r--r--xml-rpc.php10
12 files changed, 30 insertions, 95 deletions
diff --git a/backend.php b/backend.php
index fa116458c..b298ec738 100644
--- a/backend.php
+++ b/backend.php
@@ -46,15 +46,7 @@
return;
}
- if (DB_TYPE == "pgsql") {
- pg_query("set client_encoding = 'UTF-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
+ init_connection($link);
$op = $_REQUEST["op"];
diff --git a/errors.php b/errors.php
index dc47f38e4..bd7b53fe4 100644
--- a/errors.php
+++ b/errors.php
@@ -28,4 +28,6 @@
official site for more information.");
$ERRORS[11] = "[This error is not returned by server]";
+
+ $ERRORS[12] = __("SQL escaping test failed, check your database and PHP configuration");
?>
diff --git a/functions.php b/functions.php
index e1f4a229f..48d6e3a85 100644
--- a/functions.php
+++ b/functions.php
@@ -1980,6 +1980,10 @@
}
}
+ if (db_escape_string("testTEST") != "testTEST") {
+ $error_code = 12;
+ }
+
error_reporting (DEFAULT_ERROR_LEVEL);
if ($error_code != 0) {
@@ -5843,4 +5847,16 @@
function feed_has_icon($id) {
return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
}
+
+ function init_connection($link) {
+ if (DB_TYPE == "pgsql") {
+ pg_query("set client_encoding = 'UTF-8'");
+ pg_set_client_encoding("UNICODE");
+ } else {
+ if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
+ db_query($link, "SET NAMES " . MYSQL_CHARSET);
+ // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
+ }
+ }
+ }
?>
diff --git a/mobile/tt-rss.php b/mobile/tt-rss.php
index 11316d4d3..a8bf6fb5f 100644
--- a/mobile/tt-rss.php
+++ b/mobile/tt-rss.php
@@ -13,15 +13,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
- if (DB_TYPE == "pgsql") {
- pg_query("set client_encoding = 'UTF-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
+ init_connection($link);
login_sequence($link, true);
diff --git a/mysql_convert_unicode.php b/mysql_convert_unicode.php
index 6fe72994c..6d43c234c 100644
--- a/mysql_convert_unicode.php
+++ b/mysql_convert_unicode.php
@@ -9,16 +9,8 @@
require_once "db.php";
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
-
- if (DB_TYPE == "pgsql") {
- pg_query($link, "set client_encoding = 'utf-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
+
+ init_connection($link);
login_sequence($link);
diff --git a/opml.php b/opml.php
index 35d7a070c..44e94ee37 100644
--- a/opml.php
+++ b/opml.php
@@ -10,16 +10,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
- if (DB_TYPE == "pgsql") {
- pg_query($link, "set client_encoding = 'utf-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
-
+ init_connection($link);
login_sequence($link);
$owner_uid = $_SESSION["uid"];
diff --git a/update.php b/update.php
index f59f9ef3e..76e308856 100644
--- a/update.php
+++ b/update.php
@@ -9,17 +9,8 @@
require_once "db.php";
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
-
- if (DB_TYPE == "pgsql") {
- pg_query($link, "set client_encoding = 'utf-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
+ init_connection($link);
login_sequence($link);
$owner_uid = $_SESSION["uid"];
diff --git a/update_daemon.php b/update_daemon.php
index 67a8781de..35177edd6 100644
--- a/update_daemon.php
+++ b/update_daemon.php
@@ -57,6 +57,8 @@
"Maybe another daemon is already running.\n");
}
+ // Testing database connection.
+ // It is unnecessary to start the fork loop if database is not ok.
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!$link) {
@@ -67,16 +69,6 @@
return;
}
- if (DB_TYPE == "pgsql") {
- pg_query("set client_encoding = 'utf-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
-
db_close($link);
$last_purge = 0;
diff --git a/update_daemon2.php b/update_daemon2.php
index be652777e..08f5d74c3 100644
--- a/update_daemon2.php
+++ b/update_daemon2.php
@@ -113,7 +113,6 @@
db_close($link);
-
while (true) {
// Since sleep is interupted by SIGCHLD, we need another way to
@@ -155,15 +154,7 @@
return;
}
- if (DB_TYPE == "pgsql") {
- pg_query("set client_encoding = 'utf-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
- // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
+ init_connection($link);
// We disable stamp file, since it is of no use in a multiprocess update.
// not really, tho for the time being -fox
diff --git a/update_daemon_loop.php b/update_daemon_loop.php
index 737194aee..b1197ff34 100644
--- a/update_daemon_loop.php
+++ b/update_daemon_loop.php
@@ -54,15 +54,7 @@
return;
}
- if (DB_TYPE == "pgsql") {
- pg_query("set client_encoding = 'utf-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
+ init_connection($link);
$last_purge = 0;
diff --git a/update_feeds.php b/update_feeds.php
index 139da6999..2bb91dc30 100644
--- a/update_feeds.php
+++ b/update_feeds.php
@@ -36,15 +36,7 @@
return;
}
- if (DB_TYPE == "pgsql") {
- pg_query("set client_encoding = 'utf-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
+ init_connection($link);
// Purge all posts (random 30 feeds)
global_purge_old_posts($link, true, 30);
diff --git a/xml-rpc.php b/xml-rpc.php
index 0117657d0..2a23f57f6 100644
--- a/xml-rpc.php
+++ b/xml-rpc.php
@@ -19,15 +19,7 @@
return;
}
- if (DB_TYPE == "pgsql") {
- pg_query("set client_encoding = 'utf-8'");
- pg_set_client_encoding("UNICODE");
- } else {
- if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
- db_query($link, "SET NAMES " . MYSQL_CHARSET);
-// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
- }
- }
+ init_connection($link);
function getVirtualFeeds($msg) {
global $link;