Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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 如何将xls转换为mysql?_Php_Mysql_Csv_Silverstripe - Fatal编程技术网

Php 如何将xls转换为mysql?

Php 如何将xls转换为mysql?,php,mysql,csv,silverstripe,Php,Mysql,Csv,Silverstripe,如何使用PHP将大型xls或csv数据集转换为mysql数据,最好使用Silverstripe API?我可以直接这样做,还是需要先转换为文本?示例#1读取并打印CSV文件的全部内容 Example #1 Read and print the entire contents of a CSV file <?php $row = 1; if (($handle = fopen("test.csv", "r")) !== FALSE) { while (($data = fgetcsv

如何使用PHP将大型xls或csv数据集转换为mysql数据,最好使用Silverstripe API?我可以直接这样做,还是需要先转换为文本?

示例#1读取并打印CSV文件的全部内容
Example #1 Read and print the entire contents of a CSV file
<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}
?>

SilverStripe有多种方法可以将CSV文件导入到数据模型中

本节中的文档值得一读:

最快捷、最简单的方法是使用
ModelAdmin
界面管理自定义
DataObject
,并使用内置的CSV导入器

class PlayerAdmin extends ModelAdmin {
    private static $managed_models = array(
        'Player'
    );
    private static $url_segment = 'players';
}
当您转到播放器
ModelAdmin
时,您将在左侧看到一个CSV导入表单。确保CSV文件中的列标题与数据对象的变量名对齐


要了解更复杂的导入方法,请阅读文档中允许您这样做的替代方法。

csv-php有内置函数:etc,对于xls,有-mysql可以导入csv