How to trace/fix an SQL syntax error? - php

I'm trying to import a huge database file to my local dev environment to fix some errors I'm getting on the Magento back-end. I fixed the issue where it wouldn't import based on size, time, and memory. Now I've uncovered this gem of an error which says that my SQL syntax is wrong.
Not sure how that's possible because this is the exact file we're using in production but still, it's driving me nuts. Any help is appreciated.
SQL query:
DELIMITER ; ;
MySQL said: Documentation
#1064 - 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 'CREATE*/ /!50017 DEFINER=root#localhost/ /*!50003 TRIGGER
trg_catalog_prod' at line 1
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`#`localhost`*/ /*!50003 TRIGGER trg_catalog_product_website_after_insert
AFTER INSERT
ON catalog_product_website FOR EACH ROW
BEGIN
INSERT IGNORE INTO `cataloginventory_stock_status_cl` (`product_id`) VALUES (NEW.`product_id`);
INSERT IGNORE INTO `catalogsearch_fulltext_cl` (`product_id`) VALUES (NEW.`product_id`);
INSERT IGNORE INTO `catalog_product_index_price_cl` (`entity_id`) VALUES (NEW.`product_id`);

Related

Why $wpdb->insert() makes sql syntax error?

I am using wpdb->insert to insert a row to the table,
like this
$wpdb->insert($table_name, array("title"=>"foo"));
$wpdb->last_query returns the below query
INSERT INTO `some_table` (`title`) VALUES ('foo')
But i get a error in sql syntax
WordPress database 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 '1' at line 1
The error is little confusing, i passed a string 'foo' in to insert statement, but somehow it is showing '1' in the error.
This error occurs when i am running the $wpdb->insert inside phpunit, i copied the query and ran it on my test wordpress database and this query works correctly in the different method in the same test suite, it works fine.Any idea how to fix this error?
Please try this code. The recommended way (as noted in codex):
$wpdb->insert($table_name,array('title'=>'foo'),array('%s'));

XAMPP MYSQL PHPMYADMIN database import Error #1064

Having a heck of a time getting a site running locally.
Working with XAMPP for open source preferences over WAMP (no one is sure what WAMPS GPML license is apparently).
I've tried compatibility modes : None : Oracle : Traditional : MYSQL40
I've tried encoding : utf8 : utf16
Apache and SQL run perfectly but when using PHPMyAdmin to import the website database I continually get errors regarding syntax errors in the table data itself.
I attribute this to XAMPPs default incorporation of MariaDB in the latest release I'm using. I can import this database dump easily on another host's virtual SQL 5.5 server. I can also upload this database into WAMP without errors.
Looking this row over it doesn't stand out from any other rows empty fields or data fields.
MySQL: Error
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
Field1, Field2, Field3, etc,... atline 123
Interestingly the first table is created and stops short. The sequence of rows are consistent until 241 jumps to 245, then 272, and then crashes with error above on row 447?
MySql Error logs are also changing based on encoding options. Not sure if I'm digging myself into a hole while I resolve the unknown.
Most of the Event Viewer MySql Error Logs show:
Missing system table mysql.roles_mapping; please run mysql_upgrade to create it
Just upgrade MySql, what type of an update is that? What about upgrading MariaDB?
And a few of these:
Incorrect definition of table mysql.proc: expected column 'sql_mode' at position 14 to have type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVA
Playing with export options I get this error from the first Create Table Statement:
CREATE TABLE IF NOT EXISTS "Table1" (
"PRIMARY" int(123) NOT NULL AUTO_INCREMENT,
"COLUMN1" varchar(123) NOT NULL DEFAULT 'A',
"COLUMN2" int(123) NOT NULL DEFAULT '0',
"COLUMN3" varchar(123) DEFAULT NULL,
ETC...
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"TABLE" (
"ID" int(123) NOT NULL AUTO_INCREMENT,
"COLUMN1" varchar(123) N' at line 1
Currently picking through the data dump on Notepad++
Thank you in advance!
Not doube-quotes (") around column names, backtics (`).
Nothing you mentioned indicates a need to change the CHARACTER SET (encoding).
One of your errors points to sql_mode; let's see it in context.

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

I have renamed my database in phpMyAdmin but it makes some problems. When I tried to rename it to its first name, it asked first if I want to rename it and drop my database.
When I press OK, it give me this 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 qetary2015-02-21.gps_poss
The SQL query:
ALTER TABLE qetary2015-02-21.gps_poss
How can I fix it please?
At a guess:
ALTER TABLE `qetary2015-02-21`.gps_poss
Wrap the database name in backticks, else the - character might be misinterpreted as a minus sign.... though I hope there's slightly more to your SQL query than that snippet

Error creating a trigger MYSQL PHPMyadmin

Hi this is my first Question here so I'm just posting some of my code here if you need some more information on the problem please ask.
I'm trying to create a trigger is MYSQL via PHPMyadmin (yes I know not the best tool).
The idea is to be able to clean a string before the insert query executes. Simple enough.
My code:
CREATE TRIGGER `CLEAR` BEFORE INSERT ON `TABLE`
FOR EACH ROW BEGIN
SET NEW.LNAME = REPLACE(NEW.LNAME,'?','');
END;
However I keep getting this error message
#1064 - 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 3
I have no idea why. any ideas are welcome thanks before hand.
Also excuse my not so good ise of the english language, I'm not a native speaker.
You've got to change the DELIMITER before the CREATE statement and set it back afterwards:
DELIMITER |
CREATE TRIGGER `CLEAR` BEFORE INSERT ON `TABLE`
FOR EACH ROW BEGIN
SET NEW.LNAME = REPLACE(NEW.LNAME,'?','');
END |
DELIMITER ;
otherwise you could write your trigger so it needs no delimiter:
CREATE TRIGGER `CLEAR` BEFORE INSERT ON `TABLE`
FOR EACH ROW
SET NEW.LNAME = REPLACE(NEW.LNAME,'?','')
Because there's only one statement executed in the trigger body, you don't have to enclose it in a BEGIN... END block and have no need of the semicolon to enc the statement too.

MySql query - syntax error

The following code is an SQL query that I am using in PHP.
$sql = "INSERT INTO updates (update,user_id_fk)
VALUES ('$post_update','$username')";
It does not work - I get the following error message when it is run.
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 'update,user_id_fk)
This syntax loks fine to me - it is the same as I found on W3Schools.
The mysql verion I am using is 5.5.24
update is a reserved keyword backtick it
INSERT INTO updates (`update`,user_id_fk)
check the list below and in future do not use these words for your table or column names
http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Categories