"value1")) you can use this function with ($table, array_keys ($array), $array) in it's options * All arrays and values should have been cleaned before passing. It's not neccessary to add quotes. * * @param string Table to insert into * @param mixed A single value or array of values to insert (can be a multiple amount of rows) * * @return mixed False in case of error or invalid values passed. Affected rows otherwise */ function mysql_process_sql_insert($table, $values) { //Empty rows or values not processed if (empty ($values)) return false; $values = (array) $values; $query = sprintf ("INSERT INTO `%s` ", $table); $fields = array (); $values_str = ''; $i = 1; $max = count ($values); foreach ($values as $field => $value) { //Add the correct escaping to values if ($field[0] != "`") { $field = "`".$field."`"; } array_push ($fields, $field); if (is_null ($value)) { $values_str .= "NULL"; } elseif (is_int ($value) || is_bool ($value)) { $values_str .= sprintf ("%d", $value); } else if (is_float ($value) || is_double ($value)) { $values_str .= sprintf ("%f", $value); } else { $values_str .= sprintf ("'%s'", $value); } if ($i < $max) { $values_str .= ","; } $i++; } $query .= '('.implode (', ', $fields).')'; $query .= ' VALUES ('.$values_str.')'; return process_sql ($query, 'insert_id'); } /** * This function comes back with an array in case of SELECT * in case of UPDATE, DELETE etc. with affected rows * an empty array in case of SELECT without results * Queries that return data will be cached so queries don't get repeated * * @param string SQL statement to execute * * @param string What type of info to return in case of INSERT/UPDATE. * 'affected_rows' will return mysql_affected_rows (default value) * 'insert_id' will return the ID of an autoincrement value * 'info' will return the full (debug) information of a query * * @return mixed An array with the rows, columns and values in a multidimensional array or false in error */ function mysql_process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true) { global $config; global $sql_cache; $retval = array(); if ($sql == '') return false; if ($cache && ! empty ($sql_cache[$sql])) { $retval = $sql_cache[$sql]; $sql_cache['saved']++; add_database_debug_trace ($sql); } else { $start = microtime (true); if ($dbconnection == '') { $result = mysql_query ($sql); } else { $result = mysql_query ($sql, $dbconnection); } $time = microtime (true) - $start; if ($result === false) { $backtrace = debug_backtrace (); $error = sprintf ('%s (\'%s\') in %s on line %d', mysql_error (), $sql, $backtrace[0]['file'], $backtrace[0]['line']); add_database_debug_trace ($sql, mysql_error ()); set_error_handler ('sql_error_handler'); trigger_error ($error); restore_error_handler (); return false; } elseif ($result === true) { if ($rettype == "insert_id") { $result = mysql_insert_id (); } elseif ($rettype == "info") { $result = mysql_info (); } else { $result = mysql_affected_rows (); } add_database_debug_trace ($sql, $result, mysql_affected_rows (), array ('time' => $time)); return $result; } else { add_database_debug_trace ($sql, 0, mysql_affected_rows (), array ('time' => $time)); while ($row = mysql_fetch_assoc ($result)) { array_push ($retval, $row); } if ($cache === true) $sql_cache[$sql] = $retval; mysql_free_result ($result); } } if (! empty ($retval)) return $retval; //Return false, check with === or !== return false; } /** * * Escape string to set it properly to use in sql queries * * @param string String to be cleaned. * * @return string String cleaned. */ function mysql_escape_string_sql($string) { $str = mysql_real_escape_string($string); return $str; } ?>