“错误1003”和“错误0”在创建MySQL表时。 [英] "Error 1003" and "Error 0" when creating MySQL tables.

查看:146
本文介绍了“错误1003”和“错误0”在创建MySQL表时。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从CSV文件创建MySQL表时,我不断收到这些错误。



I keep getting these errors when I create MySQL tables from CSV files.

ERROR
 - Error No: 1103
 - Error: Incorrect table name 'Hospital_Value_Based_Purchasing__HVBP____Healthcare_Associated_Infection_Scores'
 - Call: Function createTableFromCSV in /home/dojob/public_html/drydo.com/csv_to_mysql/csv_to_mysql.php on line 46
ERROR
 - Error No: 0
 - Error:
 - Call: Function createTableFromCSV in /home/dojob/public_html/drydo.com/csv_to_mysql/csv_to_mysql.php on line 46





创建表的脚本





Script that creates the tables

require "MySQL_wrapper.class.php";

$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 ".csv"*/
    $file_info = pathinfo($line);
    $file_name = $file_info['filename'];


    
/*Replace "-" with "_" to be readable for server */
    $file_name = preg_replace('/-/','_',$file_name);





使用preg_replace时有更多错误。当我不使用preg_replace时,我将15个表放入数据库中,当我使用preg_replace时,我得到4个表。





There's more Errors when preg_replace is used. I get 15 tables into the database when not using preg_replace and I get 4 tables when I'm using preg_replace.

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







方法createTableFromCSV






Method createTableFromCSV

/**Creates table from CSV file and imports CSV data to Table with possibility to update rows while import.
 * @param   string      $file           - CSV File path
 * @param   string      $table          - Table name
 * @param   string      $delimiter      - COLUMNS TERMINATED BY (Default: ',')
 * @param   string      $enclosure      - OPTIONALLY ENCLOSED BY (Default: '"')
 * @param   string      $escape         - ESCAPED BY (Default: '\')
 * @param   integer     $ignore         - Number of ignored rows (Default: 1)
 * @param   array       $update         - If row fields needed to be updated eg date format or increment (SQL format only @FIELD is         variable with content of that field in CSV row) $update = array('SOME_DATE' => 'STR_TO_DATE(@SOME_DATE, "%d/%m/%Y")', 'SOME_INCREMENT' => '@SOME_INCREMENT + 1')
 * @param   string      $getColumnsFrom - Get Columns Names from (file or generate) - this is important if there is update while inserting (Default: file)
 * @param   string      $newLine        - New line delimiter (Default: auto detection use \n, \r\n ...)
 * @return  number of inserted rows or false
 */

推荐答案

filename = ' csv_list .TXT;
filename = 'csv_list.txt';


contents = file(
contents = file(


filename);


/ * 循环遍历CSV文件列表并为其创建表格每个CSV文件* /
foreach(
filename); /* Loops through list of CSV-files and create a table for each CSV-file */ foreach(


这篇关于“错误1003”和“错误0”在创建MySQL表时。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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