MySQL statement becomes corrupted during query
I am making a custom wordpress page with php. When I execute the request it gives below error:
You have an error in your SQL syntax; check the manual corresponding to the MySQL server version for the correct syntax to use next to 'brand VARCHAR (70), serialCode VARCHAR (70), QRCodeAddress VARCHAR (70), email VAR' on line 1
As you can see, you can see a strange char that usually comes from an encoding problem. But I am surprised that if I iterate over my sql expression it has no problem. See below:
CREATE TABLE SerialTable(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,brand
VARCHAR(70),serialCode VARCHAR(70),QRCodeAddress VARCHAR(70),email VARCHAR
(70),sex VARCHAR(70),age VARCHAR(70),purchasePath VARCHAR(70),expiryDate
VARCHAR(70),registeredDate VARCHAR(70),modelName VARCHAR(70),colorCode VARCHAR
(70))
And it even works well if I love the MySql shell.
My procedure is this:
- I am reading a
UTF-8
csv
file to read table column information. - Depending
csv
on the file information, make the SQL statement as above and store it in a variable$sqlStr
- when i echo
$sqlStr
it has no syntax error and even works in the MySql shell. - But when
$wpdb->query($sqlStr)
, it gives an error as above. - I have tried using
mysqli_query($conn, $sqlStr)
. and it gives the same error.
MySql Server Information:
Of course the connection is localhost as long as the web server and mysql server are on the same machine.
MySql server collation : utf8_general_ci
mysql server charset : latin_swedish_ci
I tried to fix this issue for over 48 hours and got completely stuck?
source to share