我将csv脚本导入mysql时遇到问题:从现在起,我可以将csv的数据放到mysql中,但只能使用严格的标头排列方式,但是我从csv的导出始终会更改表的头,并且我无法控制它。我的csv文件与表格不同,例如:Name Status Last_name email_address employee_address phone_number我所需要做的就是获取列名,并将其放入表的正确列中。谢谢。if (isset($_POST["import"])) {$fileName = $_FILES["file"]["tmp_name"];if ($_FILES["file"]["size"] > 0) { $file = fopen($fileName, "r"); $captabel = true; $flag = true; while (($column = fgetcsv($file, 1000, ",")) !== FALSE) { if($captabel) { $captabel = false; continue; } $celuleNecesare = array(0); foreach ($celuleNecesare as $value) { if(trim($column[$value]) == "" || $column[$value] == NULL) $flag = false; } if($flag) { $query = "INSERT into test (name ,employee_status, surname, email, address, phone) values ('" . $column[2] . "','" . $column[7] . "','" . $column[8] . "','" . $column[5] . "','" . $column[0] . "','0" . $column[3] . "')"; $result = mysqli_query($conn, $query); if (! empty($result)) { $type = "success"; header( 'refresh: 0; success.php' ); } else { $type = "error"; $message = "Problem in Importing CSV Data"; } } }}}
1 回答
- 1 回答
- 0 关注
- 176 浏览
添加回答
举报
0/150
提交
取消