文章地址:https://blog.lmlyz.online/index/detail/id/85.html
$config_link = @mysqli_connect("127.0.0.1", "root", "root", "db_name", "3306");
if (!$config_link) {
die('Could not connect: '. mysqli_error() ."\n");
}
@mysqli_query($config_link,"set names utf8");
$_tmpRes = @mysqli_query($config_link,"select * from `table_name`");
if(!$_tmpRes) die("SQL(fetchRow):{$sql} ".mysqli_error($config_link));
while ($res = mysqli_fetch_assoc($_tmpRes)) {
$result[] = $res;
}
$tmp_value = "";
$tmp_key = "";
if (!empty($result)) {
foreach ($result as $key => $value) {
$tmp_key = '(`'.implode('`,`', array_keys($value)).'`) values ';
$tmp_value .= '("'.implode('","', array_values($value)).'"),';
}
$sql = "insert into `table_name`".$tmp_key.$tmp_value;
$sql = substr($sql, 0, -1).';';
}
print_r($sql);exit();