Receiving MySQL Error in PHPMyAdmin - php

BACKGROUND: I am using PHPMyAdmin tool to run MySQL queries. MySQL version is 5.1.55. I have been using MySQL and this PHPMyAdmin tool for about 7 years and have never seen this error. I am trying to do a simple update query changing ne to gb (column = team, table = info). When I use PHPMyAdmin to try to make the changes,
I get the error message:
UPDATE `pickem`.`info` SET `team` = 'gb' WHERE CONVERT(`info`.`team` USING utf8) = \'ne\'.
QUESTION: What is going wrong here? What is the CONVERT Using UTF8 message coming from. How can I get this to just update the fields I want? I have tried to type the SQL code in myself ex: update info set team ="gb" where team = "ne" , but that does not work either. I get the error message:
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unknown Punctuation String # 22
STR: =\
SQL: update info set team =\"gb\" where team = \"ne\"
It seems the system is putting the slashes in there and it is not letting me do this simple update query.
I appreciate any advice on how to fix this.
Thanks!

You are using phpMyAdmin, right? Try using HeidiSQL.
Also check your PHP version, gpc_magic_quotes is already removed at PHP 5.4.0
I tried running your code on phpMyAdmin, removed the backslashes at \'ne\' and its running fine.
Try running a simple update query in HeidiSQL and check if the problem exists.
UPDATE `pickem`.`info` SET `team` = 'gb'
If it runs fine, modify it like
UPDATE `pickem`.`info` SET `team` = 'gb' WHERE `team` = 'ne'
Additional sidenote - check the encoding and data types. You might have overlooked something...
If your query runs fine on HeidiSQL, you can safely assume that something is wrong with your phpMyAdmin installation/configuration
EDIT:
Are the values you are providing contain '\' inside them? If so, you have to do it like
UPDATE `pickem`.`info` SET `team` = 'gb\\'
EDIT 2:
For the meantime, try to use this to solve your problem temporarily.
UPDATE `pickem`.`info` SET `team` = CONCAT('en') WHERE `team` = CONCAT('gb')
EDIT 3:
If all else fails, you probably should get this or this. Since you are on PHP 5.3, I am afraid to say that the gpc_magic_quotes option might have been enabled by your hosting provider. Contact them.

Related

CodeIgniter adds new line characters in my query

I wanted to update a column in my database table, the update should just add a numeric value to the existing one.
But this time around, I'm writing the query with CodeIgniter Query builder, the issue is that when I run the script, CodeIgniter throws an Sql Exception below:
"message": "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 '11:01:37\nWHERE `user_id` = '26'' at line 1"
As you can see, it added a new line character to the query string.
The PHP code below is the query in CodeIgniter
$userModel->set('reputations', 'reputations+10', false)
->where('user_id', $user_id)
->update();
One thing I noticed is that if I removed the false (the third parameter) which tells CodeIgniter not to escape the column name, there won't be any error, instead '0' will be updated at reputation column.
I don't know what the problem might be, I could have moved on by writing a custom query, but, I wanted to be sure that I'm not doing something wrong.
P.S: custom one will look like this:
UPDATE users
SET reputations = reputations + 10 WHERE user_id = $user_id
Note: in the above error message you might be wondering where the digits in the error came from i.e
'11:01:37 in '11:01:37\nWHERE user_id
It is the value of a column in my table which is also updating along side reputation column.
Thanks amigos.
Could it be your code editor generating the newline?
Anyways, one fast way to avoid the problem is to use codeigniter query method:
$userModel->query("UPDATE `users` SET `reputations` = reputations + 10 WHERE `user_id` = $user_id)
Not the cleanest solution but it makes sure it works! :)
Mattia

Problems with ORDER BY after LEFT JOIN [duplicate]

Hey, I've been investigating SQL_BIG_SELECTS, but the MySQL documentation so far has been pretty unhelpful. I'm looking for some insight as to preventing errors like the one below from appearing.
ERROR 1104: The SELECT would examine too many records and probably take a very long time.
Check your WHERE and use SET OPTION SQL_BIG_SELECTS=1 if the SELECT is ok
At how many rows does MySQL decide that a query is a "BIG SELECT"?
Will proper indexing usually solve this issue?
Is SQL_BIG_SELECTS considered a "last resort", or is it good practice?
How would someone set "SQL_BIG_SELECTS=1" in configuration (without having to execute the query)?
Are there any other alternatives worth knowing?
Thanks in advance!
MySQL determines whether or not a query is a 'big select' based on the value of 'max_join_size'. If the query is likely to have to examine more than this number of rows, it will consider it a 'big select'. Use 'show variables' to view the value of the max join size.
I believe that indexing and particular a good where clause will prevent this problem from occuring.
SQL_BIG_SELECTS is used to prevent users from accidentally executing excessively large queries. It is okay to set it to ON in mysql.cnf or using the command-line option at startup.
You can set SQL_BIG_SELECTS in my.cnf or at server startup. It can also be set on a session basis with SET SESSION SQL_BIG_SELECTS=1.
Not that I can think of. I would just check your query to make sure that you really need to use it. Our servers have it turned on by default, and max_join_size is very large.
You cannot set SQL_BIG_SELECTS in my.cnf or at server startup as it is a session only parameter. I am using MySQL 5.0.60.
As someone has post before, you can not set SQL_BIG_SELECTS on my.cnf at server startup. This kind of variable does not support that.
I had a same problem with a Symfony application showing this annoying error:
The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay
But you can increase the number of varialbe
max_join_size which is related to sql_big_selects
I was able to fix it executing a command as privileged mysql user:
# SET GLOBAL max_join_size=18446744073709551615;
Or you can include it in my.cnf because max_join_size is allowed to set up in configuration file
Well, I hope this can help someone else.
I had more than 2000k records in db, and my query was big-select with exhaustive comparison for duplication removal and updation of certain field...I was told the same by mysql (current version on answer date), and I ended up using index on 2 fields involved in where clause...this should help others too...steps which worked for me were:
Set Index on field
ANALYZE TABLE
run the query
HTH
Following command works for me
SET GLOBAL max_join_size=18446744073709551615;
But what do i need to put in my.cnf file instead of the command?
Btw, i'm using "5.6.12 MySQL Community Server"
SET SESSION SQL_BIG_SELECTS =1;# MySQL returned an empty result set (i.e. zero rows).
SELECT a.`HACtrl` , b.`HBCtrl` , c.`HDCtrl`
FROM `HO110BLote` AS a
LEFT JOIN `HO113BPago` AS b ON ( b.HBHACtrl = a.HACtrl )
LEFT JOIN `HO113BRecibos` AS c ON ( c.HDHBCtrl = b.HBCtrl )
WHERE HAManzana = '03'
AND HALote = '09'
LIMIT 0 , 100

How to get MySQL error if i try to UPDATE to MySQL negative values?

I have some columns in my MySQL DB declared as "smallint(6) UNSIGNED".
Those columns must not have negative values. My problem is that, whenever i'm trying to set manually from phpmyadmin (browse tab) a negative number, phpmyadmin displays an error.
If i try to set a negative value from my PHP Codeigniter application, the negative number is stored as 0 and there is no error.
My SQL update from Codeigniter is this:
UPDATE `table_example` SET `d1` = -2 WHERE `field_example` = '11' AND `field_example` = '0' AND `field_example` = 1
I want the above SQL command to return me an error to my PHP application, but currently it doesn't. It is excecuted (tried the above SQL UPDATE in phpmyadmin and it is successful, even if from phpmyadmin-browse manually changing it fails!) and the value is 0. I don't want it to be 0, i want to get an error from mysql like "Hey fool, you can't update those fields as negative numbers. Here, grab this error".
In fact, i am using transaction in Codeigniter, but it doesn't rollback. That's logical because the above SQL UPDATE is executed successfully! But how? Thanks in advance.
try this sql before your query:
mysql> SET sql_mode = '';
more info about modes can be found here: https://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-setting

mysql_query Update of varchar doesn´t work with "-"

I'm trying to find out what the problem is since hours. I have a varchar(255).
works:
mysql_query("UPDATE `servers` SET `url`='quicktest' WHERE `id`=63");
doesn't work:
mysql_query("UPDATE `servers` SET `url`='quick-test' WHERE `id`=63");
What is wrong with the "-" chars that it doesn't work? I mean I can update it in phpmyadmin without problems and sometimes it even works via mysql_query. (1 of 20 cases)
About mysql_query I know that it is outdated but it is just updating internal stuff.
Update #1
I did not had this problem on an old debian 6 server but since it is on ubuntu 13.10 with maria db and php5-fpm I can´t use this script any more and I don´t get any errors.
Update #2
As it looks like it was related to either caching via the apache modules or the google pagespeed module.
Not a solution, but maybe it's worth to try:
$temp_url = mysql_real_escape_string('quick-test');
mysql_query("UPDATE `servers` SET `url`='".$temp_url."' WHERE `id`=63");

Stumped on why MySQL won't accept my query?

Okay, so I'm currently using mysqli_real_escape_string to escape my SQL queries before sending them to MySQL via PHP. Yet, for some reason my queries aren't processing, and when I outputted the MySQL query and pasted it in to PHPMyAdmin, it gave the following error:
#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 'WHERE ind={A$RTkAIqah0J1N$Fqymnud9s5PwnWw2wC.Y02oDo4H3W8QJPoJ$6$KK8UearuUCDH$FQg' at line 1
Now, the following is my query:
INSERT INTO `db`.table(`colheader`) VALUES ('{\"hey\":[\"Hello world\",\"7\\/9\\/2013\"]}') WHERE ind='$6$RTkAIqah0J1N$Fqymnud9s5PwnWw2wC.Y02oDo4H3W8QJPoJ$6$KK8UearuUCDH$FQgSnLHIlkBOtDTzu9AuZIZTr6GS4Rzr.iW11041994'
Now, I know that the string assigned to 'ind' has some issues, but I tried putting a slash before every period and every dollar sign and it still doesn't work. I tried putting the whole thing in double quotes, even brackets. Nothing. Could anyone point out what I'm clearly missing? I've looked at the documentation and can't seem to find anything. Thank you in advance!!
WHERE serves to filter which records will be affected or retrieved by your query, and INSERT servers to append a whole new record to a table.
An INSERT can never affect existing records, therefore its nonsense to have a WHERE clause. INSERT does not support WHERE.
If you are trying to edit the value of a field on an existing record, use UPDATE instead.
Take a look at the MySQL Reference Manual for details about its usage.
if your trying to make an update to the specified index use
UPDATE `db`.table SET `colheader` = '{\"hey\":[\"Hello world\",\"7\\/9\\/2013\"]}' WHERE ind='$6$RTkAIqah0J1N$Fqymnud9s5PwnWw2wC.Y02oDo4H3W8QJPoJ$6$KK8UearuUCDH$FQgSnLHIlkBOtDTzu9AuZIZTr6GS4Rzr.iW11041994'

Categories