Mercurial > hg > fapweb
changeset 1108:c7093ad17858
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 16 May 2019 21:57:32 +0300 |
parents | 0a2117349f46 |
children | ac3bd4e94555 |
files | msitegen.inc.php |
diffstat | 1 files changed, 21 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/msitegen.inc.php Tue May 14 14:45:36 2019 +0300 +++ b/msitegen.inc.php Thu May 16 21:57:32 2019 +0300 @@ -546,6 +546,23 @@ } +function stConnectSQLDB() +{ + global $db; + try { + $db = new PDO(stGetSetting("sqlDB"), + stGetSetting("sqlUsername", NULL), + stGetSetting("sqlPassword", NULL), + stGetSetting("sqlOptions", array())); + } + catch (PDOException $e) { + stLogError("Could not connect to SQL database: ".$e->getMessage()."."); + return FALSE; + } + return ($db !== FALSE); +} + + function stDBGetSQLParam($dbh, $type, $value) { switch ($type) @@ -561,30 +578,13 @@ } -function stConnectSQLDB() +function stDBPrepareSQLUpdate($dbh, $table, $cond, $pairs, $values = NULL) { - global $db; - try { - $db = new PDO(stGetSetting("sqlDB"), - stGetSetting("sqlUsername", NULL), - stGetSetting("sqlPassword", NULL), - stGetSetting("sqlOptions", array())); - } - catch (PDOException $e) { - stLogError("Could not connect to SQL database: ".$e->getMessage()."."); - return FALSE; - } - $db = stConnectSQLDBSpec(stGetSetting("sqlDB")); - return ($db !== FALSE); -} - - -function stDBPrepareSQLUpdate($dbh, $table, $cond, $pairs) -{ - $sql = array(); + $sql = []; foreach ($pairs as $name => $attr) { - $sql[] = $name."=".stDBGetSQLParam($dbh, $attr, $name); + $sql[] = $name."=".stDBGetSQLParam($dbh, + $attr, $values !== NULL ? $values[$name] : $name); } return "UPDATE ".$table." SET ".implode(",", $sql).