【问题标题】:CSV Matrix into MysqlCSV 矩阵到 Mysql
【发布时间】:2012-08-08 08:57:32
【问题描述】:

我正在尝试让这段代码正常工作,因为它正是我所追求的: 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 in C:\xampp\htdocs\matrix\index.php 第 24 行

第 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] 是矩阵的头部。

【问题讨论】:

  • 你有没有调试过$this->contents[$line_nr][(int) $position]实际上是什么?

标签: php csv


【解决方案1】:

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

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

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

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

$csv->get_field_names();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 2013-03-08
    相关资源
    最近更新 更多