CSV矩阵进入Mysql

时间:2012-08-08 08:57:33

标签: php csv

我正在尝试使用此代码,因为它正是我所追求的: http://www.reloadedpc.com/php/php-convert-csv-price-matrix-mysql-table/

虽然我收到了这个错误:

  

警告:array_merge()[function.array-merge]:参数#1不是   第580行的C:\ xampp \ htdocs \ matrix \ Csv.php中的数组

     

警告:array_merge()[function.array-merge]:参数#1不是   第580行的C:\ xampp \ htdocs \ matrix \ Csv.php中的数组

     

警告:array_merge()[function.array-merge]:参数#1不是   第580行的C:\ xampp \ htdocs \ matrix \ Csv.php中的数组

     

致命错误:无法访问受保护的属性Csv :: $ field_names   第24行的C:\ xampp \ htdocs \ matrix \ index.php

第580行是Csv.php的以下内容:

$this->contents[$line_nr][(int) $position] = array_merge( $this->contents[$line_nr][(int) $position] );

和index.php的第24行(和第23行)是:

//get the row of width increments
$stack = $csv->field_names;

可以在此处查看Csv.php文件: http://hg.mijnpraktijk.com/csv-library/src/e4397b31002d/Csv.php

有什么建议吗?

谢谢大家。

- 编辑 - 整个代码块是:

 foreach ( $this->contents as $line_nr => $line )
                {

                        if ( array_key_exists( (int) $position, $this->contents[$line_nr] ) )
                        {
                             $return[$line_nr] = $this->contents[$line_nr][(int) $position];
                                unset( $this->contents[$line_nr][(int) $position] );
                                // reindex after removal
                                $this->contents[$line_nr][(int) $position] = array_merge($this->contents[$line_nr][(int) $position] );
                        }
                }

似乎没有设置它。 $ this-> contents [$ line_nr] [(int)$ position]是矩阵的标题。

1 个答案:

答案 0 :(得分:1)

如果你看一下错误的最后一行,它会说:

  

致命错误:无法在第24行的C:\ xampp \ htdocs \ matrix \ index.php中访问受保护的属性Csv :: $ field_names

现在转到您发布的Csv.php链接并查看代码,您会看到确实field_names被定义为:protected $field_names = array();,这意味着除非您延长,否则无法直接访问它Csv课程。

如果您不想扩展此类,只需使用公共方法:

$csv->get_field_names();