Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #16950
| Newsgroups | comp.lang.php |
|---|---|
| Date | 2016-08-20 09:15 -0700 |
| Message-ID | <2d416b5e-e923-4d44-bcbf-6956d2436ef2@googlegroups.com> (permalink) |
| Subject | PHP Warning: extract() expects parameter 1 to be array |
| From | Alla <modelling.data@gmail.com> |
Hello!
I have written a small file that extracts information from a txt file passed in as a command line
argument, and inserts all information, line by line, into sql table. When I run the program, I get
a warning:
PHP Warning: extract() expects parameter 1 to be array, boolean given in /home/ubuntu/workspace/pset8/bin/import on line 30
PHP Stack trace:
PHP 1. {main}() /path/to/file:0
PHP 2. extract() /path/to/file:30
Warning: extract() expects parameter 1 to be array, boolean given in /path/to/file on line 30
Call Stack:
0.0015 241368 1. {main}() /path/to/file:0
20.7551 334832 2. extract() /path/to/file:30
Line 30 is this one extract($new_entry);
I have checked the extract() function, and had some issues with it, which are now resolved
thanks to great help I received here. I have checked mysql connection, and it's fine.
Now, even though I get this warning, which I don't understand,
sql table is filled in with the data from txt file, and I don't get an error message at any of the passes
of the while loop.
Here is my code. I will be grateful for your help.
<?php
require(__DIR__ . "/../includes/config.php");
if($argc < 2)
echo "Please, provide a path to a file\n";
else
{
$file = $argv[1];
if(!file_exists($file))
echo "Sorry, there is no such file $file\n";
else if(!($open_file = fopen($file, "r")))
echo "Sorry, couldn't open $file\n";
else if(!is_readable($file))
echo "$file is not readable\n";
else if(filesize($file)==0)
echo "Seems there is not content in the file $file\n";
else
{
while(!feof($open_file))
{
$new_entry = fgetcsv($open_file, 0, "\t");
// var_dump($new_entry);
extract($new_entry);
$entry0 = $new_entry[0];
$entry1 = $new_entry[1];
$entry2 = $new_entry[2];
$entry3 = $new_entry[3];
$entry4 = $new_entry[4];
$entry5 = $new_entry[5];
$entry6 = $new_entry[6];
$entry7 = $new_entry[7];
$entry8 = $new_entry[8];
$entry9 = $new_entry[9];
$entry10 = $new_entry[10];
$entry11 = $new_entry[11];
//below is a customized query function from a library that is included by config.php
$row = query("INSERT INTO `places`(`country_code`, `postal_code`, `place_name`,
`admin_name1`,
`admin_code1`, `admin_name2`, `admin_code2`, `admin_name3`, `admin_code3`, `latitude`,
`longitude`,
`accuracy`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $entry0, $entry1, $entry2, $entry3, $entry4,
$entry5, $entry6, $entry7, $entry8, $entry9, $entry10, $entry11);
if($row < 1)
exit("Unable to extract data");
}
fclose($open_file);
}
}
?>
Thank you very much!
Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread
PHP Warning: extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 09:15 -0700
Re: PHP Warning: extract() expects parameter 1 to be array "R.Wieser" <address@not.available> - 2016-08-20 18:48 +0200
Re: PHP Warning: extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 10:16 -0700
Re: PHP Warning: extract() expects parameter 1 to be array "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-08-20 19:28 +0200
Re: PHP Warning: extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 11:00 -0700
Re: PHP Warning: extract() expects parameter 1 to be array "R.Wieser" <address@not.available> - 2016-08-20 21:05 +0200
Re: PHP Warning: extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 10:58 -0700
Re: PHP Warning: extract() expects parameter 1 to be array Tim Streater <timstreater@greenbee.net> - 2016-08-20 18:21 +0100
Re: PHP Warning: extract() expects parameter 1 to be array "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-08-20 20:16 +0200
Re: PHP Warning: extract() expects parameter 1 to be array "R.Wieser" <address@not.available> - 2016-08-20 21:26 +0200
Re: PHP Warning: extract() expects parameter 1 to be array Tim Streater <timstreater@greenbee.net> - 2016-08-20 22:05 +0100
Re: PHP Warning: extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 22:39 -0700
Re: PHP Warning: extract() expects parameter 1 to be array Tim Streater <timstreater@greenbee.net> - 2016-08-21 10:26 +0100
Re: PHP Warning: extract() expects parameter 1 to be array Jerry Stuckle <jstucklex@attglobal.net> - 2016-08-21 10:10 -0400
Re: PHP Warning: extract() expects parameter 1 to be array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-21 16:55 +0100
Re: PHP Warning: extract() expects parameter 1 to be array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-22 21:34 +0200
Re: PHP Warning: extract() expects parameter 1 to be array Jerry Stuckle <jstucklex@attglobal.net> - 2016-08-22 19:13 -0400
Re: PHP Warning: extract() expects parameter 1 to be array Matthew Carter <m@ahungry.com> - 2016-08-23 01:26 -0400
Re: PHP Warning: extract() expects parameter 1 to be array Jerry Stuckle <jstucklex@attglobal.net> - 2016-08-23 08:08 -0400
csiph-web