在CSV上传时自动构建mySql表 [英] Automatically build mySql table upon CSV upload

查看:389
本文介绍了在CSV上传时自动构建mySql表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CSV档案上传时自动建立mySql表格。



我有一个管理员区段,管理员可以上传CSV档案, p>



它应该在db中构建一个mySql表,它将读取第一行并创建列,然后相应地导入数据。 p>

我知道类似问题




  • 表的名称应该是文件的名称减去扩展名[.csv])

  • 每个csv文件可以不同

  • 应该从CSV文件创建一个包含列数和名称的表

  • 添加第二行和
  • 上的数据


这里是设计草图



也许有已知的框架使这很容易。
谢谢。

解决方案

http://bytes.com/topic/mysql/answers/746696-create-mysql-table-field-headings-line-csv-file 有一个很好的例子,如何做到这一点。



第二个例子应该把你放在正确的轨道,没有一些自动的方式做到这一点你需要做一个lil编程,但是一旦你实现了代码作为起点,它不应该太难。


Automatically build mySql table upon a CSV file upload.

I have a admin section where admin can upload CSV files with different column count and different column name.


which it should then build a mySql table in the db which will read the first line and create the columns and then import the data accordingly.

I am aware of a similar issue, but this is different because of the following specs.

  • The name of the Table should be the name of the file (minus the extension [.csv])
  • each csv file can be diffrent
  • Should build a table with number of columns and names from the CSV file
  • add the the data from the second line and on

Here is a design sketch

Maybe there are known frameworks that makes this easy. Thanks.

解决方案

http://bytes.com/topic/mysql/answers/746696-create-mysql-table-field-headings-line-csv-file has a good example of how to do this.

The second example should put you on the right track, there isn't some automatic way to do it so your going to need to do a lil programming but it shouldn't be too hard once you implement that code as a starting point.

这篇关于在CSV上传时自动构建mySql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆