这是我的代码,我一直收到错误但不知道原因。我试图将我的代码转换为使用加载数据infile,而不是使用insert插入循环,因此它将运行得更快。我可以插入这个就好了但是当我尝试加载数据infile它似乎没有工作。
以下是错误消息:无法加载。用户'root'@'localhost'拒绝访问(使用密码:YES)
<!DOCTYPE html>
<head>
</head>
<body>
<?php
//mysql login creds
$username = "root";
$password = "XXXX";
$hostname = "localhost";
//This is the var that holds the connection
$earthScores = file_get_contents('earthfeed.txt', 'r');
//mysql connection
$conn = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select DB to work with
mysql_select_db("eetoolsx_earthfeed",$conn)
or die("Could not select alliance_news_feed");
//clear table before writing new
mysql_query('TRUNCATE TABLE scores');
$result = mysql_query("LOAD DATA INFILE '$earthScores'" .
" INTO TABLE scores FIELDS TERMINATED BY ','");
if(!$result){
die("Could not load. " .mysql_error());
}
mysql_close($conn);
?>
</body>
</html>
答案 0 :(得分:1)
LOAD DATA INFILE
需要一个文件名,但您将文件内容传递给它。