Maurits van der Schee 10 years ago
parent
commit
f86aa53e9e
1 changed files with 7 additions and 12 deletions
  1. 7
    12
      index.php

+ 7
- 12
index.php View File

@@ -131,31 +131,26 @@ function retrieveObject($key,$table,$mysqli) {
131 131
 function createObject($input,$table,$mysqli) {
132 132
 	if (!$input) return false;
133 133
 	$keys = implode('`,`',array_map(function($v){ return preg_replace('/[^a-zA-Z0-9\-_]/','',$v); },array_keys((array)$input)));
134
-	$values = implode("','",array_map(function($v){ return $mysqli->real_escape_string($v); },array_values((array)$input)));
134
+	$values = implode("','",array_map(function($v) use ($mysqli){ return $mysqli->real_escape_string($v); },array_values((array)$input)));
135 135
 	$mysqli->query("INSERT INTO `$table[0]` (`$keys`) VALUES ('$values')");
136 136
 	return $mysqli->insert_id;
137 137
 }
138 138
 
139 139
 function updateObject($key,$input,$table,$mysqli) {
140 140
 	if (!$input) return false;
141
-	$pk = findPrimaryKey($table,$database,$mysqli);
142 141
 	$sql = "UPDATE `$table[0]` SET ";
143
-	foreach (array_keys($input) as $i=>$k) {
142
+	foreach (array_keys((array)$input) as $i=>$k) {
144 143
 		if ($i) $sql .= ",";
145
-		$v = $input[$k];
144
+		$v = $input->$k;
146 145
 		$sql .= "`$k`='$v'";
147 146
 	}
148
-	$sql .= " WHERE `$pk`='$key'";
147
+	$sql .= " WHERE `$key[1]`='$key[0]'";
149 148
 	$mysqli->query($sql);
150 149
 	return $mysqli->affected_rows;
151 150
 }
152 151
 
153
-function deleteObject($key,$input,$table,$mysqli) {
154
-	if (!$input) return false;
155
-	$pk = findPrimaryKey($table,$database,$mysqli);
156
-	if (!$pk) return false;
157
-	$sql = "DELETE FROM `$table[0]` WHERE `$pk`='$key'";
158
-	$mysqli->query($sql);
152
+function deleteObject($key,$table,$mysqli) {
153
+	$mysqli->query("DELETE FROM `$table[0]` WHERE `$key[1]`='$key[0]'");
159 154
 	return $mysqli->affected_rows;
160 155
 }
161 156
 
@@ -238,7 +233,7 @@ switch($action){
238 233
 		endOutput($callback);
239 234
 		break;
240 235
 	case 'delete':
241
-		if (!$input) exitWith404();
236
+		if (!$object) exitWith404();
242 237
 		startOutput($callback);
243 238
 		echo json_encode(deleteObject($key,$table,$mysqli));
244 239
 		endOutput($callback);

Loading…
Cancel
Save