我正在尝试将文件导入到数据库中,无论我做了什么更改,我都会收到相同的错误。错误是——
您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以获取在第 1 行的“1”附近使用的正确语法
似乎无法找到解决方案。我究竟做错了什么?谢谢 :)
<?php
$conn = mysqli_connect('localhost','root');
if (!$conn) {
die(mysqli_error());
}
$db = mysqli_query($conn,"CREATE DATABASE IF NOT EXISTS monthly");
if (mysqli_query($conn,$db)){
echo "Database created";
} else {
echo "Database not created: " . mysqli_error($conn);
}
mysqli_select_db($conn, "monthly");
$ct = mysqli_query($conn,"CREATE TABLE IF NOT EXISTS `month1`(
`week1` INT(4) NOT NULL,
`week2` INT(4) NOT NULL,
`week3` INT(4) NOT NULL,
`week4` INT(4) NOT NULL
)");
if (mysqli_query($conn,$ct)){
echo "Table created";
} else {
echo "table not created: " . mysqli_error($conn);
}
$open = fopen('/xampp/htdocs/month1.txt','r');
while (!feof($open))
{
$getTextLine = fgets($open);
$explodeLine = explode(',',$getTextLine, 4);
if(count($explodeLine) !=4) {
continue;
}
$week1 = $explodeLine[0];
$week2 = $explodeLine[1];
$week3 = $explodeLine[2];
$week4 = $explodeLine[3];
list($week1,$week2,$week3,$week4) = $explodeLine;
$qry = "insert into 'month1' ('week1','week2','week3','week4') values('$week1','$week2','$week3','$week4')" or die(mysqli_error());
mysqli_query($conn,$qry);
}
fclose($open);
mysqli_close($conn);
?>
临摹微笑
拉丁的传说