Re: Text from Excel csv file loaded into MySQL table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Lynch wrote:
Ah...

Try something like this:

<?php
  $file = fopen($filename, "r") or die("Could not open $filename");
  while (!feof($file)){
    $values = fgetcsv($file, 1000000);
    array_walk($values, 'mysql_real_escape_string');
    $values_sql = implode("', '", $values);
    $query = "insert into invw2wfinal ";
    $query .= "values('$values') ";
    $result = mysql_query($query) or die(mysql_error());
  }
?>

This assumes that no record (all 4 fields) with overhead is move than
1Mb in size -- Change the 1000000 if you have monster fields.  And
count on needing to tweak my.cnf in that case anyway.
Looks a lot neater than my code! Is it version dependent? Running on MySQL 4.1.21 and PHP 4.4.4 (not my Server so I can't control that) generates the following warnings:-

"mysql_real_escape_string() expects parameter 2 to be resource, integer" for each of the fields then when it goes to do the query it returns "Column count doesn't match value count at row 1", if I echo the query it reads "insert into invw2wtest values('Array')".


Thanks,

Alan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux