]> git.wh0rd.org - tt-rss.git/blobdiff - include/db.php
Merge pull request #89 from alsvartr/auth_radius
[tt-rss.git] / include / db.php
index 1401c089b0474e2cf4f64ee89ac2e8ebd736a1d7..a70a1d87889ad4528141e966e4aee5711c2431b0 100644 (file)
@@ -15,14 +15,14 @@ function db_connect($host, $user, $pass, $db) {
                        $string .= " host=$host";
                }
 
-               if (defined('DB_PORT')) {
+               if (defined('DB_PORT') && DB_PORT) {
                        $string = "$string port=" . DB_PORT;
                }
 
                $link = pg_connect($string);
 
                if (!$link) {
-                       die("Connection failed: " . pg_last_error($link));
+                       die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
                }
 
                return $link;
@@ -36,26 +36,22 @@ function db_connect($host, $user, $pass, $db) {
                        }
                        return $link;
                } else {
-                       die("Connection failed: " . mysql_error($link));
+                       die("Unable to connect to database (as $user to $host, database $db): " . mysql_error());
                }
        }
 }
 
-function db_escape_string($s, $strip_tags = true) {
+function db_escape_string($link, $s, $strip_tags = true) {
        if ($strip_tags) $s = strip_tags($s);
 
        if (DB_TYPE == "pgsql") {
-               return pg_escape_string($s);
+               return pg_escape_string($link, $s);
        } else {
-               return mysql_real_escape_string($s);
+               return mysql_real_escape_string($s, $link);
        }
 }
 
 function db_query($link, $query, $die_on_error = true) {
-       //if ($_REQUEST["qlog"])
-       //      error_log($_SESSION["uid"] . ":" . $_REQUEST["op"] . "/" . $_REQUEST["method"] .
-       //              " $query\n", 3, "/tmp/ttrss-query.log");
-
        if (DB_TYPE == "pgsql") {
                $result = pg_query($link, $query);
                if (!$result) {