From 5c372ead52147b3677bd67e52fcd9e4164a4c38d Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 23 Sep 2007 13:33:50 +0000 Subject: [PATCH] functions.inc.php: add a db_get_boolean($bool) function to handle the 0/1/False/True stuff for MySQL&PostgreSQL git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@73 a1433add-5e2c-0410-b055-b7f2511e0802 --- functions.inc.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/functions.inc.php b/functions.inc.php index abb5bc04..c551af0c 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1256,7 +1256,32 @@ function db_connect () } } +/** + * Returns the appropriate boolean value for the database. + * Currently only PostgreSQL and MySQL are supported. + * @param boolean $bool (REQUIRED) + * @return String or int as appropriate. + */ +function db_get_boolean($bool) { + if(!is_boolean($bool)) { + die("Invalid usage of 'db_get_boolean($bool)'"); + } + global $CONF; + if($CONF['database_type']=='pgsql') { + // return either true or false (unquoted strings) + if($bool) { + return 'true'; + } + return 'false'; + } + elseif($CONF['database_type'] == 'mysql') { + if($bool) { + return 1; + } + return 0; + } +} // // db_query