Created
March 22, 2018 08:43
-
-
Save storyflow/dfc9470795d2cda2a6e1792e8aac50d7 to your computer and use it in GitHub Desktop.
【Mysql】批量插入数据
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function insert_batch($table, $data) | |
{ | |
global $ms_import; | |
$keys = array_keys(current($data)); | |
$values = []; | |
foreach ($data as $clean) { | |
foreach ($clean as $kk=>$vv) { | |
$clean[$kk] = '\'' . addslashes($vv) . '\''; | |
} | |
$values[] = '('.implode(',', $clean).')'; | |
} | |
$sql = _insert_batch($table, $keys, $values); | |
$res = $ms_import->query($sql); | |
return $res; | |
} | |
function _insert_batch ($table, $keys, $values) | |
{ | |
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment