prepare($sql); // Check for errors if(!$stmt) { echo "Error preparing statement: " . $db->lastErrorMsg(); return; } // Bind the parameters $paramTypes = str_repeat('s', count($columnsArr)); foreach($valuesArr as $i => $value) { $stmt->bindValue($i + 1, $value); } foreach($idsArr as $i => $idValue) { $stmt->bindValue(count($valuesArr) + $i + 1, $idValue); } // Execute the statement $result = $stmt->execute(); $changes = $db->changes(); if ($changes == 0) { // Insert new value create($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values); } // update cache $uniqueHash = hash('ripemd160', $dbtable . $columns); setCache($uniqueHash, $values, $expireMinutes); echo 'OK' ; } //------------------------------------------------------------------------------ // create //------------------------------------------------------------------------------ function create($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values) { global $db; echo "NOT IMPLEMENTED!\n\n"; return; // // Insert new value // $sql = 'INSERT INTO '.$dbtable.' ('.$columns.') // VALUES ("'. quotes($parameter) .'", // "'. $values .'")'; // $result = $db->query($sql); // if (! $result == TRUE) { // echo "Error creating entry\n\n$sql \n\n". $db->lastErrorMsg(); // return; // } } //------------------------------------------------------------------------------ // delete //------------------------------------------------------------------------------ function delete($columnName, $id, $dbtable) { global $db; // Handle one or multiple ids if(strpos($id, ',') !== false) { $idsArr = explode(",", $id); } else { $idsArr = array($id); } // Initialize an empty string to store the comma-separated list of IDs $idsStr = ""; // Iterate over each ID foreach ($idsArr as $index => $item) { // Append the current ID to the string $idsStr .= '"' . $item . '"'; // Add a comma if the current ID is not the last one if ($index < count($idsArr) - 1) { $idsStr .= ', '; } } // Construct the SQL query to delete entries based on the given IDs $sql = 'DELETE FROM '.$dbtable.' WHERE "'.$columnName.'" IN ('. $idsStr .')'; // Execute the SQL query $result = $db->query($sql); // Check if the query executed successfully if (! $result == TRUE) { // Output an error message if the query failed echo "Error deleting entry\n\n$sql \n\n". $db->lastErrorMsg(); return; } else { // Output 'OK' if the deletion was successful echo 'OK' ; return; } } ?>