LOAD DATA LOCAL INFILE仅输入5行

时间:2016-10-17 12:59:53

标签: php mysql csv load-data-infile

我有一个csv文件,我使用LOAD DATA LOCAL INFILE命令将其加载到mysql中,但我不知道为什么它只读取5行。 这是我的PHP代码:

<?php
include "../config.php";
$conn = new mysqli( $servername, $username, $password, $dbname );
if ( $conn->connect_error ) {
    die( "Connection failed: " . $conn->connect_error );
} //$conn->connect_error

$sql= "LOAD DATA LOCAL INFILE 'uploads/cell.csv'
INTO TABLE table3
CHARACTER SET UTF8
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'";
$result           = $conn->query( $sql );
echo("Error description: " . mysqli_error($conn));
?>

并且csv文件附在下面的链接中。

cell.csv

执行php代码后的Mysql如下所示:

mysql

1 个答案:

答案 0 :(得分:0)

我终于自己弄明白了,问题是/ r / n,somr用/ r完成,有些用/ r / n完成,我把代码换成了:

<?php
include "../config.php";
$conn = new mysqli( $servername, $username, $password, $dbname );
if ( $conn->connect_error ) {
    die( "Connection failed: " . $conn->connect_error );
} //$conn->connect_error

$sql= "LOAD DATA LOCAL INFILE 'uploads/cell.csv'
INTO TABLE table3
CHARACTER SET UTF8
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r'";
$result           = $conn->query( $sql );
echo("Error description: " . mysqli_error($conn));
?>

它解决了这个问题。