[Fusionforge-commits] r7766 - branches/Branch_4_5/gforge/common/include

Roland Mas lolando at libremir.placard.fr.eu.org
Mon Jun 8 10:52:48 CEST 2009


Author: lolando
Date: 2009-06-08 10:52:48 +0200 (Mon, 08 Jun 2009)
New Revision: 7766

Modified:
   branches/Branch_4_5/gforge/common/include/database.php
Log:
Added implementation of pg_query_params() for older releases of PHP

Modified: branches/Branch_4_5/gforge/common/include/database.php
===================================================================
--- branches/Branch_4_5/gforge/common/include/database.php	2009-06-08 08:40:05 UTC (rev 7765)
+++ branches/Branch_4_5/gforge/common/include/database.php	2009-06-08 08:52:48 UTC (rev 7766)
@@ -160,6 +160,28 @@
 	return $res;
 }
 
+// Stolen from php.net for older releases of PHP
+if( !function_exists( 'pg_query_params' ) ) {
+	
+	function pg_query_params__callback( $at ) {
+		global $pg_query_params__parameters;
+		return $pg_query_params__parameters[ $at[1]-1 ];
+	}
+	
+	function pg_query_params( $db, $query, $parameters ) {
+		
+		// Escape parameters as required & build parameters for callback function
+		global $pg_query_params__parameters;
+		foreach( $parameters as $k=>$v )
+			$parameters[$k] = ( is_int( $v ) ? $v : "'".pg_escape_string( $v )."'" );
+		$pg_query_params__parameters = $parameters;
+		
+		// Call using pg_query
+		return pg_query( $db, preg_replace_callback( '/\$([0-9]+)/', 'pg_query_params__callback', $query ) );
+		
+	}
+}
+
 /* Current transaction level, private variable */
 /* FIXME: Having scalar variable for transaction level is
    no longer correct after multiple database (dbservers) support




More information about the Fusionforge-commits mailing list