svn commit: r294 - trunk/mapbender/http/php/database-pgsql.php
uli at osgeo.org
uli at osgeo.org
Tue May 16 03:01:22 EDT 2006
Author: uli
Date: 2006-05-16 07:01:22+0000
New Revision: 294
Modified:
trunk/mapbender/http/php/database-pgsql.php
Log:
prepared statements included
exception for db_query must be removed later
Modified: trunk/mapbender/http/php/database-pgsql.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/php/database-pgsql.php?view=diff&rev=294&p1=trunk/mapbender/http/php/database-pgsql.php&p2=trunk/mapbender/http/php/database-pgsql.php&r1=293&r2=294
==============================================================================
--- trunk/mapbender/http/php/database-pgsql.php (original)
+++ trunk/mapbender/http/php/database-pgsql.php 2006-05-16 07:01:22+0000
@@ -125,17 +125,10 @@
$QUERY_COUNT++;
$ret = pg_exec($qstring);
- #echo "SQL: ".$qstring;
- /*if(!$ret){
- echo db_error();
- $handle = fopen("../tmp/sql.txt", "a");
- fwrite($handle, $qstring." -- ".$_SERVER["SCRIPT_NAME"]."\n");
- fclose($handle);
- }
- */
+ $e = new mb_exception("not ps: ".$_SERVER['SCRIPT_FILENAME']." : ".$qstring);
if(!$ret){
- $e = new mb_exception("db_query($qstring)=$ret db_error=".db_error());
- }
+ $e = new mb_exception("db_query($qstring)=$ret db_error=".db_error());
+ }
return $ret;
}
/**
@@ -153,19 +146,32 @@
$types = array($types);
}
if(count($params) != count($types)){
- $e = new mb_exception("array params and array types have a different count! Sql: ".$qstring);
+ $e = new mb_exception("array params and array types have a different count in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$qstring);
}
- for ($i=0; $i<count($params); $i++){
- $needle = "$".strval($i+1);
- $tmp = '';
- if($types[$i] == 's'){ $tmp .= "'"; }
- $tmp .= $params[$i];
- if($types[$i] == 's'){ $tmp .= "'"; }
- $posa = strpos($qstring, $needle);
- $posb = strlen($needle);
- $qstring = substr($qstring,0,$posa).$tmp.substr($qstring,($posa + $posb));
+ if(PREPAREDSTATEMENTS == false){
+ for ($i=0; $i<count($params); $i++){
+ $needle = "$".strval($i+1);
+ $tmp = '';
+ if($types[$i] == 's'){ $tmp .= "'"; }
+ $tmp .= $params[$i];
+ if($types[$i] == 's'){ $tmp .= "'"; }
+ $posa = strpos($qstring, $needle);
+ $posb = strlen($needle);
+ $qstring = substr($qstring,0,$posa).$tmp.substr($qstring,($posa + $posb));
+ }
+ $r = db_query($qstring);
}
- $r = db_query($qstring);
+ else{
+ $t = md5(microtime());
+ $result = pg_prepare($t, $qstring);
+ if(!$result){
+ $e = new mb_exception("Error while preparing statement in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$qstring.", Error: ".db_error());
+ }
+ $r = pg_execute($t, $params);
+ if(!$r){
+ $e = new mb_exception("Error while executing prepared statement in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$qstring.", Error: ".db_error());
+ }
+ }
return $r;
}
/**
@@ -377,7 +383,7 @@
* Returns the last error from the database
*/
function db_error() {
- return @pg_errormessage();
+ return @pg_result_error();
}
/**
More information about the Mapbender_commits
mailing list