[Mapbender-commits] r6999 - in branches/mapbender: conf core lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Oct 1 11:01:52 EDT 2010


Author: christoph
Date: 2010-10-01 15:01:52 +0000 (Fri, 01 Oct 2010)
New Revision: 6999

Added:
   branches/mapbender/lib/database-pgsql-pdo.php
Modified:
   branches/mapbender/conf/mapbender.conf-dist
   branches/mapbender/core/globalSettings.php
   branches/mapbender/lib/database-pgsql.php
Log:
choose between pdo and legacy db wrapper (default)

Modified: branches/mapbender/conf/mapbender.conf-dist
===================================================================
--- branches/mapbender/conf/mapbender.conf-dist	2010-10-01 14:47:17 UTC (rev 6998)
+++ branches/mapbender/conf/mapbender.conf-dist	2010-10-01 15:01:52 UTC (rev 6999)
@@ -8,7 +8,7 @@
 # --------------------------------------------
 
 
-define("SYS_DBTYPE", "pgsql");
+define("SYS_DBTYPE", "pgsql"); // pgsql or pgsql-pdo
 
 # --------------------------------------------
 # database information

Modified: branches/mapbender/core/globalSettings.php
===================================================================
--- branches/mapbender/core/globalSettings.php	2010-10-01 14:47:17 UTC (rev 6998)
+++ branches/mapbender/core/globalSettings.php	2010-10-01 15:01:52 UTC (rev 6999)
@@ -92,7 +92,12 @@
 //
 // database wrapper
 //
-require_once(dirname(__FILE__) . "/../lib/database-pgsql.php"); 
+if (defined("SYS_DBTYPE") && SYS_DBTYPE === "pgsql-pdo") {
+	require_once(dirname(__FILE__) . "/../lib/database-pgsql-pdo.php");
+}
+else {
+	require_once(dirname(__FILE__) . "/../lib/database-pgsql.php");
+}
 
 //
 // class for error handling

Copied: branches/mapbender/lib/database-pgsql-pdo.php (from rev 6997, branches/mapbender/lib/database-pgsql.php)
===================================================================
--- branches/mapbender/lib/database-pgsql-pdo.php	                        (rev 0)
+++ branches/mapbender/lib/database-pgsql-pdo.php	2010-10-01 15:01:52 UTC (rev 6999)
@@ -0,0 +1,509 @@
+<?php
+# $Id:database-pgsql.php 2619 2008-07-08 15:46:11Z christoph $
+# http://www.mapbender.org/index.php/database-pgsql.php
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/**
+ * \file
+ * \brief MySQL database connection/querying layer
+ * 
+ * MySQL database connection/querying layer
+ *
+ * example:
+ * \code
+ * include_once(dirname(__FILE__)."/afwphp/database-mysql.php");  
+ * $sys_dbhost=...                            
+ * $sys_dbuser=...                            
+ * $sys_dbpasswd=...                           
+ * $sys_dbname=...                            
+ *                                             
+ * db_connect();                               
+ * ...                                         
+ * $rs = db_query("select * from table");      
+ * while($row = db_fetch_array($rs));
+ *  ...
+ * \endcode
+ */
+
+/**
+ * System-wide database type
+ *
+ * @var	constant		$sys_database_type
+ */
+$sys_database_type='pgsql';
+
+/**
+ *  Connect to the database
+ *
+ *  Notice the global vars that must be set up
+ *  Notice the global vars $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname that must be set up 
+ *  in other functions in this library
+ */
+include_once(dirname(__FILE__)."/../http/classes/class_mb_exception.php");
+include_once(dirname(__FILE__)."/../http/classes/class_checkInput.php");
+function db_escape_string($unescaped_string){
+	return @pg_escape_string(stripslashes($unescaped_string));
+}
+$DB = DB;
+
+
+function db_connect($DBSERVER="",$OWNER="",$PW="") {
+	return Mapbender::db();
+/*
+	global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug;
+	global $conn,$conn_update,$DB;	
+
+	
+	$db_debug=0;
+	if ($DBSERVER)
+		$sys_dbhost = $DBSERVER; 
+	if ($OWNER)
+		$sys_dbuser = $OWNER; 
+	if ($PW && $PW != null)
+		$sys_dbpasswd = $PW; 
+	
+	$sys_dbport = PORT; 	
+		
+	if($GLOBALS['DB'])
+		$sys_dbname = $DB;
+			
+	$connstring = "";
+	if ($sys_dbuser)		
+		$connstring.=" user=$sys_dbuser";
+	if ($sys_dbname)		
+		$connstring.=" dbname=$sys_dbname";		
+	if ($sys_dbhost)		
+		$connstring.=" host=$sys_dbhost";	
+	if ($sys_dbport)		
+		$connstring.=" port=$sys_dbport";		
+	if ($sys_dbpasswd)		
+		$connstring.=" password=$sys_dbpasswd";		
+	
+	if ($db_debug)
+		echo $connstring." ";		
+
+	$conn = pg_connect($connstring);		
+
+		#if(isset($sys_db_clientencoding) && $sys_db_clientencoding > "")
+		#{
+		#pg_set_client_encoding ( $conn, $sys_db_clientencoding);
+		#}
+	#return $conn;
+	if ($db_debug)
+		echo "conn=".$conn;
+#echo $connstring;
+#if(!$conn)
+#{echo "FEHLER in Connection";
+#pg_error($conn);}	
+	
+	return $conn;
+ 
+ */
+}
+
+function db_select_db($DB,$con="") {
+//	global $conn,$sys_dbname;
+#	$sys_dbname = DB;	
+#	$_con = $con ? $con : $conn;
+#	$ret = @mysql_select_db($sys_dbname,$_con);
+//	echo "$ret=@mysql_select_db($sys_dbname,$_con);";
+}
+
+/**
+ *  Query the database
+ *
+ *  @param		$qstring (string)	SQL statement
+ *  @param		$limit (int)		How many rows do you want returned
+ *  @param		$offset (int)		Of matching rows, return only rows starting here
+ */
+function db_query($qstring) {
+	return Mapbender::db()->query($qstring);
+/*
+	global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug,
+		$conn,$conn_update,$QUERY_COUNT,$DBSERVER,$OWNER,$PW,$DB;
+	$QUERY_COUNT++;
+	$ret = pg_exec($qstring);
+//	$e = new mb_exception("not ps:  ".$_SERVER['SCRIPT_FILENAME']." : ".$qstring);
+	if(!$ret){
+		$e = new mb_exception("db_query($qstring)=$ret db_error=".db_error());
+	}
+	return $ret;
+
+ */
+}
+/**
+ *  prepare and query the database
+ *
+ *  @param		$qstring (string)	SQL statement
+ *  @param		$params (array params as strings)		
+ *  @param		$types (array types as strings)		
+ */
+function db_prep_query($qstring, $params, $types){
+	for ($i = 1; $i <= count($params); $i++) {
+		$needle = "$".strval($i);
+		$posa = mb_strpos($qstring, $needle);
+		if(!$posa) {
+			$e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME']. ": Sql :". $orig_qstring .",Error: parameter '$needle' not found ");
+		}
+		$posb = mb_strlen($needle);
+		$tmp = ":name$i";
+		$qstring = mb_substr($qstring,0,$posa).$tmp.mb_substr($qstring,($posa + $posb));
+	}
+	$statement = Mapbender::db()->prepare($qstring);
+	if (!$statement) {
+		$e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME']. ": Sql :". $orig_qstring .",Error: parameter '$needle' not found ");
+		return false;
+	}
+	for ($i = 1; $i <= count($params); $i++) {
+		$statement->bindValue(":name$i", $params[$i-1]);
+	}
+
+	if(!$statement->execute()){
+		$errorMsg = $statement->errorInfo();
+		$errorMsg = $errorMsg[2];
+		$e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME']. ": Sql :". $orig_qstring .",Error: parameter '$needle' not found ");
+		return false;
+	}
+	return $statement;
+
+/*
+	$orig_qstring = $qstring;
+	$ci = new checkInput($qstring,$params,$types);
+	$params = $ci->v; 
+	if(PREPAREDSTATEMENTS == false){
+		for ($i=0; $i<count($params); $i++){
+			$needle = "$".strval($i+1);
+			$tmp = '';
+			if($params[$i] !== NULL){
+				if($types[$i] == 's'){ $tmp .= "'"; }
+				$tmp .= $params[$i];
+				if($types[$i] == 's'){ $tmp .= "'"; }
+			}
+			else{
+				$tmp .= "NULL";
+			}
+			$posa = mb_strpos($qstring, $needle);
+			if(!$posa) { 
+ 				$e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME']. ": Sql :". $orig_qstring .",Error: parameter '$needle' not found ");
+ 			}
+			$posb = mb_strlen($needle);
+			$qstring = mb_substr($qstring,0,$posa).$tmp.mb_substr($qstring,($posa + $posb));	
+		}
+		$r = db_query($qstring);
+		if(!$r){
+			$e = new mb_exception("Error while executing sql statement in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$qstring.", Error: ".db_error());
+		}
+	}
+	else{
+		$result = pg_prepare("", $qstring);
+		if(!$result){
+			$e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$qstring.", Error: ".db_error());
+		}
+		$r = pg_execute("", $params);
+		if(!$r){
+			$e = new mb_exception("Error while executing prepared statement in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$qstring.", Error: ".db_error());
+		}
+	}	
+	return $r;
+*/
+}
+/**
+ *	Begin a transaction
+ *
+ *	Begin a transaction for databases that support them
+ *	may cause unexpected behavior in databases that don't
+ */
+function db_begin() {
+	return Mapbender::db()->beginTransaction();
+//	return db_query("BEGIN WORK");
+}
+
+/**
+ * Commit a transaction
+ *
+ * Commit a transaction for databases that support them
+ * may cause unexpected behavior in databases that don't
+ */
+function db_commit() {
+	return Mapbender::db()->commit();
+//	return db_query("COMMIT");
+}
+
+/**
+ * Roll back a transaction
+ *
+ * Rollback a transaction for databases that support them
+ * may cause unexpected behavior in databases that don't
+ */
+function db_rollback() {
+	return Mapbender::db()->rollback();
+/*
+	$str = db_error();
+	db_query("ROLLBACK");
+	die('sql error: ' . $str . " ROLLBACK performed....");
+
+ */
+}
+
+/**
+ * Returns the number of rows in this result set
+ *
+ *  @param		$qhandle (string)	Query result set handle
+ */
+function db_numrows($qhandle) {
+	return $qhandle->rowCount;
+/*
+	// return only if qhandle exists, otherwise 0
+	if ($qhandle) {
+		return @pg_numrows($qhandle);
+	} else {
+		return 0;
+	}
+ *
+ */
+}
+/**
+ * Returns the number of rows in this result set
+ *
+ *  @param		$qhandle (string)	Query result set handle
+ *	php > 4.2
+ */ 
+function db_num_rows($qhandle) {
+	return $qhandle->rowCount;
+/*
+	// return only if qhandle exists, otherwise 0
+	if ($qhandle) {
+		return @pg_num_rows($qhandle);
+	} else {
+		return 0;
+	}
+ */
+}
+
+/**
+ *  Frees a database result properly 
+ *
+ *  @param	$qhandle (string)	Query result set handle
+ */
+function db_free_result($qhandle) {
+//	return @pg_freeresult($qhandle);
+}
+
+/**
+ *  Reset a result set.
+ *
+ *  Reset is useful for db_fetch_array sometimes you need to start over
+ *
+ *  @param		$qhandle (string)	Query result set handle
+ *  @param		$row (int)		Row number
+ */
+function db_reset_result($qhandle,$row=0) {
+#dummy
+//	return 0;#mysql_data_seek($qhandle,$row);
+	
+}
+
+/**
+ *  Returns a field from a result set
+ *
+ *  @param		$qhandle (string)	Query result set handle
+ *  @param		$row (int)		Row number
+ *  @param		$field (string)	Field name
+ */
+function db_result($qhandle,$row,$field) {
+	$arr = $qhandle->fetchAll();
+	return $arr[$row][$field];
+//	return @pg_result($qhandle,$row,$field);
+}
+
+/**
+ *  Returns the number of fields in this result set
+ *
+ *  @param		$lhandle (string)	Query result set handle
+ */
+function db_numfields($lhandle) {
+//	return @pg_numfields($lhandle);
+}
+
+/**
+ *  Returns the number of fields in this result set
+ *
+ *  @param		$lhandle (string)	Query result set handle
+ *	php >4.2
+ */
+function db_num_fields($lhandle) {
+	return $lhandle->columnCount();
+//	return @pg_num_fields($lhandle);
+}
+
+/**
+ *  Returns the number of rows changed in the last query
+ *
+ *  @param		$lhandle	(string) Query result set handle
+ *  @param		$fnumber (int)	Column number
+ */
+function db_fieldname($lhandle,$fnumber) {
+//	   return @pg_fieldname($lhandle,$fnumber);
+}
+
+/**
+ *  Returns the number of rows changed in the last query
+ *
+ *  @param		$qhandle (string)	Query result set handle
+ */
+function db_affected_rows($qhandle) {
+	
+//	return @pg_cmdtuples($qhandle);
+}
+
+/**
+ *  Fetch an array
+ *
+ *  Returns an associative array from 
+ *  the current row of this database result
+ *  Use db_reset_result to seek a particular row
+ *
+ *  @param		$qhandle (string)	Query result set handle
+ */
+function db_fetch_array($qhandle) {
+	return $qhandle->fetch(PDO::FETCH_BOTH);
+//	return @pg_fetch_array($qhandle);
+}
+/**                                                       
+ * fetch a row into an associative array 
+ * 
+ *  @param		$qhandle (string)	Query result set handle
+ *  @param		$fnumber (int)	Column number
+ */
+function db_fetch_assoc($qhandle) {
+	return $qhandle->fetch(PDO::FETCH_ASSOC);
+//	return @pg_fetch_assoc($qhandle);
+
+}
+function db_fetch_all($qhandle){
+	return $qhandle->fetchAll();
+//	return @pg_fetch_all($qhandle);
+}
+/**                                                       
+ * fetch a row into an array 
+ * 
+ *  @param		$qhandle (string)	Query result set handle
+ *  @param		$fnumber (int)	Column number
+ */
+function db_fetch_row($qhandle,$fnumber=0) {
+	return $qhandle->fetch(PDO::FETCH_BOTH);
+//	return pg_fetch_row($qhandle);
+}
+
+/**
+ *  Returns the last primary key from an insert
+ *
+ *  @param		$qhandle (string)	Query result set handle
+ *  @param		$table_name (string)	Is the name of the table you inserted into
+ *  @param		$pkey_field_name (string)	Is the field name of the primary key
+ */
+function db_insertid($qhandle="",$table_name="",$pkey_field_name="") {
+	$res = Mapbender::db()->query("SELECT max($pkey_field_name) AS id FROM $table_name");
+    if ($res && db_numrows($res) > 0) {
+        return @db_result($res,0,'id');
+    } else {
+        return 0;
+    }
+/*
+	$res=db_query("SELECT max($pkey_field_name) AS id FROM $table_name");
+    if ($res && db_numrows($res) > 0) {
+        return @db_result($res,0,'id');
+    } else {
+        return 0;
+    }
+ */
+}
+
+
+
+
+function db_insert_id($qhandle="",$table_name="",$pkey_field_name="") {
+	return db_insertid($qhandle, $table_name, $pkey_field_name);
+/*
+	global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug,
+		$conn,$conn_update,$QUERY_COUNT,$DBSERVER,$OWNER,$PW,$DB;
+  $res=db_query("SELECT max($pkey_field_name) AS id FROM $table_name");
+    if ($res && db_numrows($res) > 0) {
+        return db_result($res,0,'id');
+    } else {
+        return 0;
+    }
+ *
+ */
+}
+/*
+function db_last_oid()
+      {
+      	global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug,
+		$conn,$conn_update,$QUERY_COUNT;
+        global $DBSERVER,$OWNER,$PW,$DB	;
+             return pg_getlastoid($conn);
+      }
+*/
+
+/**
+ * Returns the last error from the database
+ */
+function db_error() {
+	return implode(", ", Mapbender::db()->errorInfo());
+//	return @pg_last_error();
+}
+
+/**
+ * Get the flags associated with the specified field in a result 
+ *
+ *  @param		$lhandle	(string) Query result set handle
+ *  @param		$fnumber (int)	Column number
+ *
+ * 					Examples: "not_null", "primary_key", "unique_key", "multiple_key",					 
+ *                    "blob", "unsigned", "zerofill","binary", "enum",                  
+ *                    "auto_increment", "timestamp"                                     
+ */
+/*
+function db_field_flags($lhandle,$fnumber) {
+	   print "db_field_flags()	isn't implemented";
+	   
+}
+*/
+/**                                                       
+ * Get the type of the specified field  
+ *
+ *  @param		$lhandle	(string) Query result set handle
+ *  @param		$fnumber (int)	Column number
+ */                                                       
+/*
+function db_field_type($lhandle,$fnumber) {               
+	   return @pg_fieldtype($lhandle,$fnumber);         
+}                                                         
+*/
+/**                                                       
+ * Get the length of the specified field                                                            
+ *
+ *  @param		$lhandle	(string) Query result set handle
+ *  @param		$fnumber (int)	Column number
+ */                                                       
+/*
+function db_field_len($lhandle,$fnumber) {               
+	   return @pg_fieldlen($lhandle,$fnumber);         
+} 
+*/
+?>

Modified: branches/mapbender/lib/database-pgsql.php
===================================================================
--- branches/mapbender/lib/database-pgsql.php	2010-10-01 14:47:17 UTC (rev 6998)
+++ branches/mapbender/lib/database-pgsql.php	2010-10-01 15:01:52 UTC (rev 6999)
@@ -62,8 +62,6 @@
 
 
 function db_connect($DBSERVER="",$OWNER="",$PW="") {
-	return Mapbender::db();
-/*
 	global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug;
 	global $conn,$conn_update,$DB;	
 
@@ -111,12 +109,10 @@
 #pg_error($conn);}	
 	
 	return $conn;
- 
- */
 }
 
 function db_select_db($DB,$con="") {
-//	global $conn,$sys_dbname;
+	global $conn,$sys_dbname; 
 #	$sys_dbname = DB;	
 #	$_con = $con ? $con : $conn;
 #	$ret = @mysql_select_db($sys_dbname,$_con);
@@ -131,8 +127,6 @@
  *  @param		$offset (int)		Of matching rows, return only rows starting here
  */
 function db_query($qstring) {
-	return Mapbender::db()->query($qstring);
-/*
 	global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug,
 		$conn,$conn_update,$QUERY_COUNT,$DBSERVER,$OWNER,$PW,$DB;
 	$QUERY_COUNT++;
@@ -141,9 +135,7 @@
 	if(!$ret){
 		$e = new mb_exception("db_query($qstring)=$ret db_error=".db_error());
 	}
-	return $ret;
-
- */
+	return $ret;	
 }
 /**
  *  prepare and query the database
@@ -153,34 +145,6 @@
  *  @param		$types (array types as strings)		
  */
 function db_prep_query($qstring, $params, $types){
-	for ($i = 1; $i <= count($params); $i++) {
-		$needle = "$".strval($i);
-		$posa = mb_strpos($qstring, $needle);
-		if(!$posa) {
-			$e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME']. ": Sql :". $orig_qstring .",Error: parameter '$needle' not found ");
-		}
-		$posb = mb_strlen($needle);
-		$tmp = ":name$i";
-		$qstring = mb_substr($qstring,0,$posa).$tmp.mb_substr($qstring,($posa + $posb));
-	}
-	$statement = Mapbender::db()->prepare($qstring);
-	if (!$statement) {
-		$e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME']. ": Sql :". $orig_qstring .",Error: parameter '$needle' not found ");
-		return false;
-	}
-	for ($i = 1; $i <= count($params); $i++) {
-		$statement->bindValue(":name$i", $params[$i-1]);
-	}
-
-	if(!$statement->execute()){
-		$errorMsg = $statement->errorInfo();
-		$errorMsg = $errorMsg[2];
-		$e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME']. ": Sql :". $orig_qstring .",Error: parameter '$needle' not found ");
-		return false;
-	}
-	return $statement;
-
-/*
 	$orig_qstring = $qstring;
 	$ci = new checkInput($qstring,$params,$types);
 	$params = $ci->v; 
@@ -219,7 +183,6 @@
 		}
 	}	
 	return $r;
-*/
 }
 /**
  *	Begin a transaction
@@ -228,8 +191,7 @@
  *	may cause unexpected behavior in databases that don't
  */
 function db_begin() {
-	return Mapbender::db()->beginTransaction();
-//	return db_query("BEGIN WORK");
+	return db_query("BEGIN WORK");
 }
 
 /**
@@ -239,8 +201,7 @@
  * may cause unexpected behavior in databases that don't
  */
 function db_commit() {
-	return Mapbender::db()->commit();
-//	return db_query("COMMIT");
+	return db_query("COMMIT");
 }
 
 /**
@@ -250,13 +211,9 @@
  * may cause unexpected behavior in databases that don't
  */
 function db_rollback() {
-	return Mapbender::db()->rollback();
-/*
 	$str = db_error();
 	db_query("ROLLBACK");
 	die('sql error: ' . $str . " ROLLBACK performed....");
-
- */
 }
 
 /**
@@ -265,16 +222,12 @@
  *  @param		$qhandle (string)	Query result set handle
  */
 function db_numrows($qhandle) {
-	return $qhandle->rowCount;
-/*
 	// return only if qhandle exists, otherwise 0
 	if ($qhandle) {
 		return @pg_numrows($qhandle);
 	} else {
 		return 0;
 	}
- *
- */
 }
 /**
  * Returns the number of rows in this result set
@@ -283,15 +236,12 @@
  *	php > 4.2
  */ 
 function db_num_rows($qhandle) {
-	return $qhandle->rowCount;
-/*
 	// return only if qhandle exists, otherwise 0
 	if ($qhandle) {
 		return @pg_num_rows($qhandle);
 	} else {
 		return 0;
 	}
- */
 }
 
 /**
@@ -300,7 +250,7 @@
  *  @param	$qhandle (string)	Query result set handle
  */
 function db_free_result($qhandle) {
-//	return @pg_freeresult($qhandle);
+	return @pg_freeresult($qhandle);
 }
 
 /**
@@ -313,7 +263,7 @@
  */
 function db_reset_result($qhandle,$row=0) {
 #dummy
-//	return 0;#mysql_data_seek($qhandle,$row);
+	return 0;#mysql_data_seek($qhandle,$row);
 	
 }
 
@@ -325,9 +275,7 @@
  *  @param		$field (string)	Field name
  */
 function db_result($qhandle,$row,$field) {
-	$arr = $qhandle->fetchAll();
-	return $arr[$row][$field];
-//	return @pg_result($qhandle,$row,$field);
+	return @pg_result($qhandle,$row,$field);
 }
 
 /**
@@ -336,7 +284,7 @@
  *  @param		$lhandle (string)	Query result set handle
  */
 function db_numfields($lhandle) {
-//	return @pg_numfields($lhandle);
+	return @pg_numfields($lhandle);
 }
 
 /**
@@ -346,8 +294,7 @@
  *	php >4.2
  */
 function db_num_fields($lhandle) {
-	return $lhandle->columnCount();
-//	return @pg_num_fields($lhandle);
+	return @pg_num_fields($lhandle);
 }
 
 /**
@@ -357,7 +304,7 @@
  *  @param		$fnumber (int)	Column number
  */
 function db_fieldname($lhandle,$fnumber) {
-//	   return @pg_fieldname($lhandle,$fnumber);
+	   return @pg_fieldname($lhandle,$fnumber);
 }
 
 /**
@@ -367,7 +314,7 @@
  */
 function db_affected_rows($qhandle) {
 	
-//	return @pg_cmdtuples($qhandle);
+	return @pg_cmdtuples($qhandle);
 }
 
 /**
@@ -380,8 +327,7 @@
  *  @param		$qhandle (string)	Query result set handle
  */
 function db_fetch_array($qhandle) {
-	return $qhandle->fetch(PDO::FETCH_BOTH);
-//	return @pg_fetch_array($qhandle);
+	return @pg_fetch_array($qhandle);
 }
 /**                                                       
  * fetch a row into an associative array 
@@ -390,13 +336,11 @@
  *  @param		$fnumber (int)	Column number
  */
 function db_fetch_assoc($qhandle) {
-	return $qhandle->fetch(PDO::FETCH_ASSOC);
-//	return @pg_fetch_assoc($qhandle);
+	return @pg_fetch_assoc($qhandle);
 
 }
 function db_fetch_all($qhandle){
-	return $qhandle->fetchAll();
-//	return @pg_fetch_all($qhandle);
+		return @pg_fetch_all($qhandle);
 }
 /**                                                       
  * fetch a row into an array 
@@ -405,8 +349,7 @@
  *  @param		$fnumber (int)	Column number
  */
 function db_fetch_row($qhandle,$fnumber=0) {
-	return $qhandle->fetch(PDO::FETCH_BOTH);
-//	return pg_fetch_row($qhandle);
+	  return pg_fetch_row($qhandle);
 }
 
 /**
@@ -417,40 +360,38 @@
  *  @param		$pkey_field_name (string)	Is the field name of the primary key
  */
 function db_insertid($qhandle="",$table_name="",$pkey_field_name="") {
-	$res = Mapbender::db()->query("SELECT max($pkey_field_name) AS id FROM $table_name");
-    if ($res && db_numrows($res) > 0) {
-        return @db_result($res,0,'id');
-    } else {
-        return 0;
-    }
-/*
 	$res=db_query("SELECT max($pkey_field_name) AS id FROM $table_name");
     if ($res && db_numrows($res) > 0) {
         return @db_result($res,0,'id');
     } else {
         return 0;
     }
- */
 }
 
 
 
 
 function db_insert_id($qhandle="",$table_name="",$pkey_field_name="") {
-	return db_insertid($qhandle, $table_name, $pkey_field_name);
-/*
-	global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug,
+		global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug,
 		$conn,$conn_update,$QUERY_COUNT,$DBSERVER,$OWNER,$PW,$DB;
-  $res=db_query("SELECT max($pkey_field_name) AS id FROM $table_name");
+	/*	
+	$oid =pg_last_oid($qhandle);
+	echo $oid;
+	
+	$res=db_query("SELECT ".$pkey_field_name." FROM ".$table_name." WHERE oid =".$oid );
     if ($res && db_numrows($res) > 0) {
+        return @db_result($res,0,0);
+    } else {
+        return 0;
+    }*/
+    $res=db_query("SELECT max($pkey_field_name) AS id FROM $table_name");
+    if ($res && db_numrows($res) > 0) {
         return db_result($res,0,'id');
     } else {
         return 0;
     }
- *
- */
 }
-/*
+
 function db_last_oid()
       {
       	global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$sys_dbname,$db_debug,
@@ -458,14 +399,13 @@
         global $DBSERVER,$OWNER,$PW,$DB	;
              return pg_getlastoid($conn);
       }
-*/
 
+
 /**
  * Returns the last error from the database
  */
 function db_error() {
-	return implode(", ", Mapbender::db()->errorInfo());
-//	return @pg_last_error();
+	return @pg_last_error();
 }
 
 /**
@@ -478,32 +418,32 @@
  *                    "blob", "unsigned", "zerofill","binary", "enum",                  
  *                    "auto_increment", "timestamp"                                     
  */
-/*
+
 function db_field_flags($lhandle,$fnumber) {
 	   print "db_field_flags()	isn't implemented";
 	   
 }
-*/
+
 /**                                                       
  * Get the type of the specified field  
  *
  *  @param		$lhandle	(string) Query result set handle
  *  @param		$fnumber (int)	Column number
  */                                                       
-/*
+                                                          
 function db_field_type($lhandle,$fnumber) {               
 	   return @pg_fieldtype($lhandle,$fnumber);         
 }                                                         
-*/
+
 /**                                                       
  * Get the length of the specified field                                                            
  *
  *  @param		$lhandle	(string) Query result set handle
  *  @param		$fnumber (int)	Column number
  */                                                       
-/*
+                                                          
 function db_field_len($lhandle,$fnumber) {               
 	   return @pg_fieldlen($lhandle,$fnumber);         
 } 
-*/
-?>
+
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list