duancui19840401 2015-12-30 20:08
浏览 52

CSV文件到MySQL,“错误号:0”

So I'm trying to create a MySQL table from a CSV file using this script: https://github.com/uzi88/PHP_MySQL_wrapper#create-table-from-csv-file

The script I'm using is a slight modification to the one in the link. The only difference is that the script I'm using is made to loop through a list. Here's the modified part:

$filename = 'csv_list.txt';
$contents = file($filename);


/* Loops through list of CSV-files and create a table for each CSV-file */
foreach($contents as $line) {

    /* Cuts off file extension */
    $file_info = pathinfo($line);
    $file_name = $file_info['filename'];

    $db->dropTable($file_name);
    $db->createTableFromCSV('/csv/'.$file_name.'.csv', $file_name);

    }

But I get the error "ERROR -> NO -> 0 - DESC -> - CALL -> Function createTableFromCSV in csv_to_mysql.php on line 32". I can't seem to find any information about this error.

Here are a few rows from the CSV file I'm trying to import.

Disease,County,Year,Sex,Count,Population,Rate,CI.lower,CI.upper,Unstable
Amebiasis,California,2001,Total,571,34514777,1.654,1.521,1.796, 
Amebiasis,California,2001,Female,176,17340743,1.015,0.871,1.176, 
Amebiasis,California,2001,Male,365,17174034,2.125,1.913,2.355, 
Amebiasis,El Dorado,2006,Total,0,175258,0,0,2.105,-
Amebiasis,El Dorado,2006,Female,0,87654,0,0,4.208,-
Amebiasis,El Dorado,2006,Male,0,87604,0,0,4.211,-
Amebiasis,El Dorado,2007,Total,1,177195,0.564,0.014,3.144,*
Amebiasis,El Dorado,2007,Female,1,88622,1.128,0.029,6.287,*

I've also tried with a new file where I removed the column "Unstable" because some values where empty. I also renamed CI.lower and CI.upper

Disease,County,Year,Sex,Count,Population,Rate,CIlower,CIupper
Amebiasis,California,2001,Total,571,34514777,1.654,1.521,1.796
Amebiasis,California,2001,Female,176,17340743,1.015,0.871,1.176
Amebiasis,California,2001,Male,365,17174034,2.125,1.913,2.355

Here's a link to the complete CSV file: https://cdph.data.ca.gov/api/views/yijp-bauh/rows.csv?accessType=DOWNLOAD

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c