Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert into values (),(),(),()... #729

Open
getchu opened this issue Mar 8, 2018 · 1 comment
Open

insert into values (),(),(),()... #729

getchu opened this issue Mar 8, 2018 · 1 comment

Comments

@getchu
Copy link

getchu commented Mar 8, 2018

public function buildSql($tableName , $sqlStack){
    $keys = \array_keys($sqlStack[0]);
    $keysStr = array();
    foreach($keys as $key){
        $keysStr[] = '`'.$key.'`';
    }
    $keysStr = \implode(',', $keysStr);
    $sql = 'INSERT INTO '.$tableName. '('.$keysStr. ') VALUES ';

    //data
    $values = array();
    foreach($sqlStack as $insertData){
        $fields = array();
        foreach($insertData as $key=>$value){
            $fields[] = is_string($value) ? '\''.$this->escape($value).'\'' : (is_null($value) ? '' : $value);
        }
        $fields = \implode(',', $fields);

        $values[] = '('.$fields.')';
    }
    $values = \implode(',', $values);

    $sql = $sql .$values . ';';


    return $sql;
}
@enrybisco
Copy link

solved null insert instead of empty:
#954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants