Mercurial > hg > fapweb
changeset 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 | f1f55db4228f |
children | b3e9c3eedc23 |
files | msitegen.inc.php |
diffstat | 1 files changed, 26 insertions(+), 0 deletions(-) [+] |
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;