Mercurial > hg > fapweb
diff msitegen.inc.php @ 547:1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
around the portability issues of PDO::lastInsertId().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 16 Dec 2013 01:25:24 +0200 |
parents | b9ce451d8ec7 |
children | 09a11dd385c7 |
line wrap: on
line diff
--- a/msitegen.inc.php Mon Dec 16 00:35:39 2013 +0200 +++ b/msitegen.inc.php Mon Dec 16 01:25:24 2013 +0200 @@ -546,6 +546,25 @@ } +function stDBExecSQLInsert($dbh, $sql) +{ + switch ($dbh->getAttribute(PDO::ATTR_DRIVER_NAME)) + { + case "pgsql": + if (($res = stDBFetchSQLColumn($dbh, $sql." RETURNING id")) !== false) + return $res; + else + return FALSE; + + default: + if (stDBExecSQL($dbh, $sql) !== false) + return $dbh->lastInsertId(); + else + return FALSE; + } +} + + function stDBExecSQL($dbh, $sql) { if (($res = $dbh->query($sql)) !== FALSE) @@ -592,6 +611,13 @@ } +function stExecSQLInsert($sql) +{ + global $db; + return stDBExecSQLInsert($db, $sql); +} + + function stExecSQL($sql) { global $db;