I have imported a number of tables (structure and data) from an MSSQL DB into mysql - all data is in UTF8
I can pull data from the old tables, but when I use any of the data from the imported tables in a query from PHP I get a syntax error like this:
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 ''data' at line 1
for this query
SELECT * FROM tableName WHERE field='data'
This only happens if executing the query from PHP, if I echo out the query from php and then copy, paste and execute the query from phpmyadmin then it runs fine.
Any ideas???
I'm using PHP 5.2.17 running on Apache 1.3.42 and MySQL 4.1.22-standard
If you using query like this then query should be :
E.G
"SELECT * FROM tableName WHERE field='data'";
or
'SELECT * FROM tableName WHERE field="data"';
Please check for "Field" data-type whether is Varchar or sumthing else!
Related
I am using laravel with mssql and getting this error with simple group by query.
RetailersModel::groupBy('state')->get();
And it returns me error.
I have migrating database server from mysql to mssql.
Mysql is running fine but error occur when try to get record from ms-sql database server.
I have also set strict false in mysql and mssql config in database php.
Thanks in advance.
RetailersModel::groupBy('state')->get();
Try to execute this query
RetailersModel::select('*','state', DB::raw('COUNT(state) as state'))->groupBy('state')->get();
I'm making Wordpress custom page with php. When I execute query, it gives error below:
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 '��brand VARCHAR(70),serialCode VARCHAR(70),QRCodeAddress VARCHAR(70),email VAR' at line 1
As you can see, you can see strange char � that usually happens from encoding problem. But what I wonder is that if I echo my sql statement, it has no any problem. Look bellow:
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 excute in MySql shell.
My procedure is like this:
I'm reading UTF-8 csv file to read table column information
Depending on csv file information, make SQL statement like above and save it in variable $sqlStr
when i echo $sqlStr, it has no any syntax error and even works in MySql shell.
But when $wpdb->query($sqlStr), it give error like above.
I tried to use mysqli_query($conn, $sqlStr) as well. and it give same error.
MySql server info:
Of course connection is localhost as long as web server and mysql server is on same computer.
MySql server collation : utf8_general_ci
mysql server charset : latin_swedish_ci
I've been trying to solve this problem for more than 48 hours and am completely stuck?
It is very likely that your CSV file contains "unprintable" characters that allow it to look normal within an editor.
Try deleting the offending line or lines and recreate them.
i've created a mysql view which is expecting 2 parameters and i'm able to query it without problems in phpyadmin with the following sql-string:
SET #date1 = '2014-02-06';
SET #date2 = '2014-02-07';
SELECT * FROM _myquery
it will not work under php - i'm getting the following error:
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 'SET #date2 = '2014-02-07'; SELECT * FROM _myquery' at line 2
when it's working in phpmyadmin, shouldn't it also work under php?
any idea what's wrong?
Do you really need the MySQL variables? because your SELECT query is not using them.
You can try just with
SELECT * FROM _myquery
But if you really need to use MySQL variables, take a look at this:
Mysql Variables not working through php mysql query
MySql variables and php
I am using a readymade script to backup my MySQL database using PHP. I store the resultant query in a variable.
If I echo the variable, and copy paste the output into the MySQL console, it works perfectly.
But when I run the same using 'mysql_query' (I know it is depreciated, kindly ignore that), I get the dreaded Syntax error.
Here's the echo output (first 2 lines) :
INSERT INTO assign
VALUES('75085','rsam','CE0001/CZ0001/CPE183/CSC183','1','1','3.0','13','1','1','13','2','10.00','117.00','0','0');INSERT
INTO assign
VALUES('75086','rsam','CE0001/CZ0001/CPE183/CSC183','1','2','3.0','13','1','1','13','2','10.00','97.50','0','0');
And here's the exact error :
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 'INSERT INTO assign
VALUES('75085','rsam','CE0001/CZ0001/CPE183/CSC183','1','1'' at line 1
If anyone can point out what I am obviously missing, I would be grateful!
As the documentation for mysql_query() says:
mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.
You might be interested in mysql_multi_query():
Executes one or multiple queries which are concatenated by a semicolon.
While mysql_query is limited to a single statement, this situation can be avoided as multiple records can be inserted into the same table with only one statement:
INSERT INTO assign (...)
VALUES(...),
VALUES(...);
This will save on round-trip latency (over multiple mysql_query) which might matter.
See Inserting multiple rows in mysql
I'm running this code in PHP:
mysql_query("SET #update_id:=NULL");
echo mysql_error();
And this is what I get:
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 1
Also this same code runs perfectly in PHPMyAdmin. What am I doing wrong?
Additional information. I'm trying to write a query described here:
How to get ID of the last updated row in MySQL?
But the problem right now is that I even can't run a simple query to create variable.
P.S. Ok, now it seems that it desn't work because of some previous queries that are not related to this one. If i move this query to the top of the php file it works. Also if I try to make this:
mysql_query("SET #update_id:=NULL; SELECT #update_id;");
It fails with syntax error. But this works fine:
mysql_query("SET #update_id:=NULL;");
mysql_query("SELECT #update_id;");
Does somebody knows what am I missing here?
Why can't I run two commands in one query and why they're the separate queries are related to each other?
mysql_query("UPDATE your_table SET update_id=NULL");
Check this it may be helpful
SELECT #update_id IN("SET #update_id:=NULL");