# HG changeset patch # User Matti Hamalainen # Date 1386422230 -7200 # Node ID e0fa6bb432d723873234bf5b68af0439129388e5 # Parent 9737c24d39d28573eaf995f68b3a97bfca3dfcf9 Add new helper functions. diff -r 9737c24d39d2 -r e0fa6bb432d7 msitegen.inc.php --- 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); }