Allowing empty insert to trigger mysql auto values

Issue #28 open
Samuel Maréchal created an issue

Whene I tried it, it raised an error, the solution to the errror was to define the arrays keys & values as empty arrays at first.

public function insert($table, $data)
{
    $keys = array();
    $values = array();

    if (isset($this -> table_prefixfix))
        $table = $this -> table_prefix . $table;

    foreach ($data as $key => $value)
    {
        $keys[] = "`$key`";
        if (strpos($value, '()') == true)
            $values[] = "$value";
        else
            $values[] = "'$value'";
    }
    $this -> _query = "INSERT INTO " . $table . " (" . implode(', ', $keys) . ") VALUES (" . implode(', ', $values) . ");";
    $this -> execute();
    return $this -> _mysqli -> insert_id;
}

Comments (6)

  1. Log in to comment