MySQL LOAD DATA INFILE不插入行

时间:2013-06-29 10:02:37

标签: php mysql sql

我正在使用MySQL LOAD DATA INFILE命令。它显示空白输出,并且没有插入mySQL DB。

mysql_connect("localhost", "user", "pwd*")or die("cannot connect");

mysql_select_db("my_db")or die("cannot select DB");

$sql="LOAD DATA LOCAL INFILE 'users.csv' INTO TABLE usersystem 
      FIELDS TERMINATED BY ',' ENCLOSED BY '"'
      LINES TERMINATED BY '\r\n'
      IGNORE 1 LINES
      (email,password,fname,lname)";

$result=mysql_query($sql);
if($result){
    echo "DONE"
}
else {
    echo "ERROR";
}
mysql_close();

为什么不插入行?

1 个答案:

答案 0 :(得分:0)

试试这个:

mysql_connect("localhost", "user", "pwd*") or die("cannot connect");
mysql_select_db("my_db") or die("cannot select DB");
$sql = "LOAD DATA LOCAL INFILE 'users.csv' INTO TABLE usersystem" .
       " FIELDS TERMINATED BY ',' ENCLOSED BY '\"'" .
       " LINES TERMINATED BY '\\r\\n'" .
       "  IGNORE 1 LINES" .
       " (email,password,fname,lname)";

$result = mysql_query($sql);
if ($result){
  echo "DONE"
}

else {
  echo "ERROR";
}

// close connection
mysql_close();

警告

<小时/> MySQL扩展名已经过时了!使用MySQLiPDO。要了解它们,请使用您最喜欢的搜索引擎。