Browse Source

Added database prepare (#38 #214 #196)

Tobias Reich 10 years ago
parent
commit
75e63a9e3a
1 changed files with 22 additions and 0 deletions
  1. 22 0
      php/modules/Database.php

+ 22 - 0
php/modules/Database.php

@@ -219,6 +219,28 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
 
 	}
 
+	static function prepare($database, $query, $data) {
+
+		# Check dependencies
+		Module::dependencies(isset($database, $query, $data));
+
+		foreach ($data as $value) {
+
+			# Escape
+			$value = mysqli_real_escape_string($database, $value);
+
+			# Replace
+			$query = preg_replace('/\?/', $value, $query, 1);
+
+		}
+
+		# Add semicolon at the end
+		$query .= ';';
+
+		return $query;
+
+	}
+
 }
 
 ?>