db::insert_all PHP Method

insert_all() static public method

Runs a INSERT query with values
static public insert_all ( string $table, array $fields, array $values ) : mixed
$table string The table name
$fields array an array of field names
$values array an array of array of keys and values.
return mixed The last inserted id if everything went fine or an error response.
    static function insert_all($table, $fields, $values)
    {
        $query = 'INSERT INTO ' . self::prefix($table) . ' (' . implode(',', $fields) . ') VALUES ';
        $rows = array();
        foreach ($values as $v) {
            $str = '(\'';
            $sep = '';
            foreach ($v as $input) {
                $str .= $sep . db::escape($input);
                $sep = "','";
            }
            $str .= '\')';
            $rows[] = $str;
        }
        $query .= implode(',', $rows);
        return db::execute($query);
    }