Mercurial > hg > fapweb
changeset 486:e0fa6bb432d7
Add new helper functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Dec 2013 15:17:10 +0200 |
parents | 9737c24d39d2 |
children | 289692a0169c |
files | msitegen.inc.php |
diffstat | 1 files changed, 30 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/msitegen.inc.php Sat Dec 07 15:16:46 2013 +0200 +++ b/msitegen.inc.php Sat Dec 07 15:17:10 2013 +0200 @@ -417,6 +417,34 @@ } +function stConnectSQLDBSpec($dbspec) +{ + try { + $dbh = new PDO($dbspec); + } + catch (PDOException $e) { + error_log("Could not connect to SQL database: ".$e->getMessage()."."); + return FALSE; + } + return $dbh; +} + + +function stDBGetSQLParam($dbh, $type, $value) +{ + switch ($type) + { + case "d": return intval($value); + case "s": return $dbh->quote($value); + case "b": return intval($value) ? 1 : 0; + case "D": return intval(stGetRequestItem($value)); + case "S": return $dbh->quote(stGetRequestItem($value)); + case "Q": return $dbh->quote(stGetRequestItem($value)); + case "B": return intval(stGetRequestItem($value)) ? 1 : 0; + } +} + + function stLogSQLError($sql) { global $db; @@ -427,14 +455,8 @@ function stConnectSQLDB() { global $db; - try { - $db = new PDO(stGetSetting("sqlDB")); - } - catch (PDOException $e) { - error_log("Could not connect to SQL database: ".$e->getMessage()."."); - return FALSE; - } - return TRUE; + $db = stConnectSQLDBSpec(stGetSetting("sqlDB")); + return ($db !== false); }