svn commit: r112 - trunk/mapbender/http/php
uli at osgeo.org
uli at osgeo.org
Wed Apr 19 11:48:54 EDT 2006
Author: uli
Date: 2006-04-19 15:48:54+0000
New Revision: 112
Modified:
trunk/mapbender/http/php/database-mysql.php
trunk/mapbender/http/php/database-pgsql.php
Log:
validation of arrays and array-counts
Modified: trunk/mapbender/http/php/database-mysql.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/php/database-mysql.php?view=diff&rev=112&p1=trunk/mapbender/http/php/database-mysql.php&p2=trunk/mapbender/http/php/database-mysql.php&r1=111&r2=112
==============================================================================
--- trunk/mapbender/http/php/database-mysql.php (original)
+++ trunk/mapbender/http/php/database-mysql.php 2006-04-19 15:48:54+0000
@@ -166,16 +166,25 @@
* @param $params (array string params)
* @param $types (array string types)
*/
-function db_prep_query($qstring, $params, $types) {
+function db_prep_query($qstring, $params, $types){
+ if(is_array($params) == false){
+ $params = array($params);
+ }
+ if(is_array($types) == false){
+ $types = array($types);
+ }
+ if(count($params) != count($types)){
+ $e = new mb_exception("array params and array types have a different count! 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 .= "'"; }
- $sql = str_replace($needle, $tmp, $qstring);
+ if($types[$i] == 's'){ $tmp .= "'"; }
+ $qstring = str_replace($needle, $tmp, $qstring);
}
- $r = db_query($sql);
+ $r = db_query($qstring);
return $r;
}
/**
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=112&p1=trunk/mapbender/http/php/database-pgsql.php&p2=trunk/mapbender/http/php/database-pgsql.php&r1=111&r2=112
==============================================================================
--- trunk/mapbender/http/php/database-pgsql.php (original)
+++ trunk/mapbender/http/php/database-pgsql.php 2006-04-19 15:48:54+0000
@@ -131,16 +131,25 @@
* @param $params (array params as strings)
* @param $types (array types as strings)
*/
-function db_prep_query($qstring, $params, $types) {
+function db_prep_query($qstring, $params, $types){
+ if(is_array($params) == false){
+ $params = array($params);
+ }
+ if(is_array($types) == false){
+ $types = array($types);
+ }
+ if(count($params) != count($types)){
+ $e = new mb_exception("array params and array types have a different count! 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 .= "'"; }
- $sql = str_replace($needle, $tmp, $qstring);
+ if($types[$i] == 's'){ $tmp .= "'"; }
+ $qstring = str_replace($needle, $tmp, $qstring);
}
- $r = db_query($sql);
+ $r = db_query($qstring);
return $r;
}
/**
More information about the Mapbender_commits
mailing list