Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP/AJAX将XML数据导入MySQL数据库不工作_Php_Mysql_Ajax_Xml - Fatal编程技术网

PHP/AJAX将XML数据导入MySQL数据库不工作

PHP/AJAX将XML数据导入MySQL数据库不工作,php,mysql,ajax,xml,Php,Mysql,Ajax,Xml,我正在尝试使用PHP/Ajax上传XML文件并将数据导入我的数据库。这一切似乎运行顺利,我有一个按钮工作和一个功能,通知我是否已上传文件,但当我去查看我的数据库,信息不存在 (我在学习一个教程,试图使它适应我自己的需要/XML文件结构) 对于更复杂的XML文件,结构是什么?还是我完全没有抓住要点。我也有同样的需求,最终使用了: 首先,您需要使用from。然后读取xls文件并将数据插入数据库 读取xls文件并将其转换为具有以下结构的PHP数组: function fileInitializer($

我正在尝试使用
PHP
/
Ajax
上传
XML
文件并将数据导入我的数据库。这一切似乎运行顺利,我有一个按钮工作和一个功能,通知我是否已上传文件,但当我去查看我的数据库,信息不存在

(我在学习一个教程,试图使它适应我自己的需要/XML文件结构)


对于更复杂的
XML
文件,结构是什么?还是我完全没有抓住要点。

我也有同样的需求,最终使用了:

首先,您需要使用from。然后读取xls文件并将数据插入数据库

读取xls文件并将其转换为具有以下结构的PHP数组:

function fileInitializer($file, $needCells){
 $array_data = array();
 require_once 'libraries/PHPExcel/PHPExcel.php';
 $objPHPExcel = new PHPExcel();
 $target_dir = "FILEPATH/".$file;
 $objReader= new PHPExcel_Reader_Excel5();
 $objReader->setReadDataOnly(true);
 $objPHPExcel = $objReader->load( $target_dir);
 $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
 $rowIndex = 0;
 foreach($rowIterator as $row){
     $cellIterator = $row->getCellIterator();
     $cellIterator->setIterateOnlyExistingCells(false); 
     if(1 == $row->getRowIndex ()) continue;

    foreach ($cellIterator as $cell) {
        foreach($needCells as $needCell){
            if($needCell['cell_name'] == $cell->getColumn()){
                $array_data[$rowIndex][$needCell['array_name']] = fai_convert_string_to_persian($cell->getCalculatedValue());
            } 
        }
    }
    $rowIndex++;
}
return $array_data;
}
$file = 'FILENAME';
$needCells = array(
     array('cell_name'=>'A', 'array_name'=>'id')
    , array('cell_name'=>'B', 'array_name'=>'full_name')
);
$array_data = fileInitializer($file, $needCells);

在完成上述过程后,在$array_data中放置一段时间,并将数据添加到数据库中

我也有同样的需要,最后使用了:

首先,您需要使用from。然后读取xls文件并将数据插入数据库

读取xls文件并将其转换为具有以下结构的PHP数组:

function fileInitializer($file, $needCells){
 $array_data = array();
 require_once 'libraries/PHPExcel/PHPExcel.php';
 $objPHPExcel = new PHPExcel();
 $target_dir = "FILEPATH/".$file;
 $objReader= new PHPExcel_Reader_Excel5();
 $objReader->setReadDataOnly(true);
 $objPHPExcel = $objReader->load( $target_dir);
 $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
 $rowIndex = 0;
 foreach($rowIterator as $row){
     $cellIterator = $row->getCellIterator();
     $cellIterator->setIterateOnlyExistingCells(false); 
     if(1 == $row->getRowIndex ()) continue;

    foreach ($cellIterator as $cell) {
        foreach($needCells as $needCell){
            if($needCell['cell_name'] == $cell->getColumn()){
                $array_data[$rowIndex][$needCell['array_name']] = fai_convert_string_to_persian($cell->getCalculatedValue());
            } 
        }
    }
    $rowIndex++;
}
return $array_data;
}
$file = 'FILENAME';
$needCells = array(
     array('cell_name'=>'A', 'array_name'=>'id')
    , array('cell_name'=>'B', 'array_name'=>'full_name')
);
$array_data = fileInitializer($file, $needCells);
完成上述过程后,在$array_数据中放置一段时间,并将数据添加到数据库中

function fileInitializer($file, $needCells){
 $array_data = array();
 require_once 'libraries/PHPExcel/PHPExcel.php';
 $objPHPExcel = new PHPExcel();
 $target_dir = "FILEPATH/".$file;
 $objReader= new PHPExcel_Reader_Excel5();
 $objReader->setReadDataOnly(true);
 $objPHPExcel = $objReader->load( $target_dir);
 $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
 $rowIndex = 0;
 foreach($rowIterator as $row){
     $cellIterator = $row->getCellIterator();
     $cellIterator->setIterateOnlyExistingCells(false); 
     if(1 == $row->getRowIndex ()) continue;

    foreach ($cellIterator as $cell) {
        foreach($needCells as $needCell){
            if($needCell['cell_name'] == $cell->getColumn()){
                $array_data[$rowIndex][$needCell['array_name']] = fai_convert_string_to_persian($cell->getCalculatedValue());
            } 
        }
    }
    $rowIndex++;
}
return $array_data;
}
$file = 'FILENAME';
$needCells = array(
     array('cell_name'=>'A', 'array_name'=>'id')
    , array('cell_name'=>'B', 'array_name'=>'full_name')
);
$array_data = fileInitializer($file, $needCells);