diff --git a/lib/appconfig.php b/lib/appconfig.php
index f3038e005322af066d5ba0e0f77cf490eeeada11..20fbb5313b8bded59f3296fc480d8cb1acc2aa38 100644
--- a/lib/appconfig.php
+++ b/lib/appconfig.php
@@ -174,12 +174,12 @@ class OC_Appconfig{
 		if($app!==false and $key!==false){
 			return false;
 		}
-		$where='WHERE';
 		$fields='`configvalue`';
+		$where='WHERE';
 		$params=array();
 		if($app!==false){
-			$where.=' `appid` = ?';
 			$fields.=', `configkey`';
+			$where.=' `appid` = ?';
 			$params[]=$app;
 			$key='configkey';
 		}else{