我需要根据csv文件的函数依赖关系从csv文件创建两个表,例如,我有一个借书表
我想把这个表分成两个表,一个表中有bookid、书名、isbn、数量、出版商、authorid、authorname,
第二个表中的借入ID、studentid、studentname、借入日期、bookid。
希望你能帮助我。
/这是我的密码/
$filetype= basename($_FILES['file']['name']);
$filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0){
$file = fopen($filename, "r");
if(substr($filetype, -3) == 'csv'){
$csvName = time() .'_'.$_FILES['file']['name'];
$target = 'csv/' . $csvName;
}
}
$primary[] = "Borrowid";
$handle = fopen($target,'r');
if(($getData = fgetcsv($handle)) !== FALSE){
$i=1;
$PK_columns = Array();
//number of columns
$num = count($getData);
$row=0;
//start count rows
$csv = Array();
$rowcount = 1;
$max_line_length = defined('MAX_LINE_LENGTH') ? MAX_LINE_LENGTH : 10000;
$header = fgetcsv($handle, $max_line_length);
$header_colcount = count($header);
while (($row = fgetcsv($handle, $max_line_length)) !== FALSE) {
$row_colcount = count($row);
if ($row_colcount == $header_colcount) {
$entry = array_combine($header, $row);
$csv[] = $entry;
}
else {
error_log("csvreader: Invalid number of columns at line " . ($rowcount + 2) . " (row " . ($rowcount + 1) . "). Expected=$header_colcount Got=$row_colcount");
return null;
}
$rowcount++;
}// end count rows
if (($handle = fopen($target, "r")) !== FALSE) {
while (($getData = fgetcsv($handle, 1000, ",")) !== FALSE) {
for ($i = 0; $i < $num; $i++) { // Loop over the data using $i as index pointer\
if (in_array($getData[$i], $primary)){
$PK_columns[] = $i; // Fetch no of PK
}
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!