peter88uk
peter88uk

Reputation: 327

CSV Matrix into Mysql

I'm trying to get this code working as it's exactly what i'm after: http://www.reloadedpc.com/php/php-convert-csv-price-matrix-mysql-table/

Although I get this error:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\xampp\htdocs\matrix\Csv.php on line 580

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\xampp\htdocs\matrix\Csv.php on line 580

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\xampp\htdocs\matrix\Csv.php on line 580

Fatal error: Cannot access protected property Csv::$field_names in C:\xampp\htdocs\matrix\index.php on line 24

Line 580 is the following of Csv.php is:

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

and Line 24 (and 23) of index.php is:

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

The Csv.php file can be viewed here: http://hg.mijnpraktijk.com/csv-library/src/e4397b31002d/Csv.php

Any suggestions?

Thanks Guys.

-EDIT- The whole code block is:

 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] );
                        }
                }

It seems to unset it. $this->contents[$line_nr][(int) $position] is header of the matrix.

Upvotes: 0

Views: 174

Answers (1)

Tomer
Tomer

Reputation: 17930

If you look at the last line of the error, it says:

Fatal error: Cannot access protected property Csv::$field_names in C:\xampp\htdocs\matrix\index.php on line 24

now go to the Csv.php link you posted and look in the code and you'll see that indeed field_names is defined as: protected $field_names = array();, this means you cannot access it directly unless you extend the Csv class.

If you don't want to extend this class just use the public method:

$csv->get_field_names();

Upvotes: 1

Related Questions