gpt4 book ai didi

php - MySQL:您的 SQL 语法有错误;第 5 行 '' 附近

转载 作者:行者123 更新时间:2023-11-29 12:25:00 26 4
gpt4 key购买 nike

我在 *.php 文件中运行此查询并收到以下错误:

LOAD DATA INFILE 'Employees.txt'
INTO TABLE employees
FIELDS TERMINATED BY ';'
ENCLOSED BY '\"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r'

回应:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 5

我正在运行 mysql 版本 5.6.17 和 php 版本 5.5.12
文本文件简单有:

"000";"Employee Name"

对于每一行。
在 phpmyadmin 中或通过 mysql 控制台使用时,查询工作正常。
PHP 代码:

<?php
date_default_timezone_set('America/New_York');
###### db ##########
$db_username = 'user';
$db_password = 'pass';
$db_name = 'dbase';
$db_host = 'localhost';
################

$query="
LOAD DATA INFILE 'Employees.txt'
INTO TABLE employees
FIELDS TERMINATED BY ';'
ENCLOSED BY '\"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r'
";
echo $query.'<br>';

//Connect to DB
$connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)
or die('could not connect to database');
echo "Connected to MySQL<br>";

mysqli_query($connecDB,$query) or die(strftime('%c')." ".mysqli_error($connecDB));
mysqli_close();
echo strftime('%c')." ok!";

?>

最佳答案

试试这个方法:

$query="
LOAD DATA LOCAL INFILE 'Employees.txt'
INTO TABLE employees
FIELDS TERMINATED BY ';'
ENCLOSED BY '\\\"'
ESCAPED BY '\\\\'
LINES TERMINATED BY '\\r'
";
echo $query.'<br>';

关于php - MySQL:您的 SQL 语法有错误;第 5 行 '' 附近,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28464481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com