0

I have a table in the database called locations which contains 2 columns(id which is auto incremented , location) , And I have a csv contains 1 column looks like : enter image description here

When I try to import that file to locations table , I get this error invalid column count in CSV input on line 1.

Also I tried CSV using LOAD DATA but I get this : MySQL returned an empty result set (i.e. zero rows)

jack
  • 151
  • 2
  • 11
  • 1
    [How to LOAD DATA INFILE in mysql with first col being Auto Increment?](https://stackoverflow.com/questions/6017032/how-to-load-data-infile-in-mysql-with-first-col-being-auto-increment#6018145) – Lukasz Szozda Mar 17 '18 at 10:47

2 Answers2

0

Maybe you should use:

$array = array_map('str_getcsv', file('file.csv'));

You have more option to check variables.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
plx
  • 1
0

If Java is supported in your machine, Use below solution

https://dbisweb.wordpress.com/

The simple configuration required to do is

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <connections>
      <jdbc name="mysql">
          <driver>com.mysql.jdbc.Driver</driver>
          <url>jdbc:mysql://localhost:3306/test1</url>
          <user>root</user>
          <password></password>
      </jdbc>
  </connections>
  <component-flow>
      <execute name="file2table" enabled="true">
          <migrate>
              <source>
                  <file delimiter="," header="false" path="D:/test_source.csv"/>
              </source>
              <destination>
                  <table connection="mysql">locations</table>
              </destination>
              <mapping>
                  <column source="1" destination="location" />
              </mapping>
          </migrate>
      </execute>
  </component-flow>
</config>

If you are interested, Same can be achieved by Java code.

Source source = new File("D:/test_source.csv", ',', false);
        Destination destination = new Table("locations", new JDBCConnection("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/test1", "root", ""));
        List<Mapping> mapping = new ArrayList<>();
        mapping.add(new Mapping("1", "location", null));
        Component component = new MigrateExecutor(source, destination, mapping);
        component.execute();
compyutech
  • 578
  • 3
  • 8
  • 26