I want to insert similar text into mysql table.
It is inserted in table but it insert like 42=(-4)2=16 ..
I want to insert it properly with square root symbol.
I guess MySQL proper collation type might be the solution but don't know which collation it may work.
As you described you tried the right collation (utf8_unicode_ci), it is not a MySQL issue. You may see the previous discussion on how to store unicode in mysql on stackoverflow.
Following these answers, I executed the followed queries:
CREATE TABLE can_square ( sqr CHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci);
INSERT INTO can_square (sqr) VALUES ( "4² = (-4)² = 16" );
And it works fine.
And I inserted the same type of data from my PHPMyAdmin successfully, both from running an SQL query and inserting manually in the insert tab. Then it also is not a PHPMyAdmin issue
As yourself spotted, its probably a string formatting issue when you copy and paste from another source. Try to type the string directly in PHPMyAdmin and see if it works. If you have to put the value manually, and you know it is happening, copy and paste may not be a good alternative.
Related
I have a MySQL database with a table with entries with accents, like "João".
The entries are selected with a MySQL++ query in C/C++ code, but this entry in particular is printed as "Jo�o" (printf, fprintf or std::cout <<).
What I'd like to understand is: where in the data flow is this character being encoded incorrectly?
Some more context: the front-end is HTML/PHP, which uses PDO to insert the data into the MySQL database.
I see the character correctly displayed with PDO queries in HTML. It is also correctly displayed with:
mysql> select * from <table>;
so I assume it is well written in the table. The problem seems to reside either with the MySQL++ query or the C/C++ output command.
I don't know if it is relevant, but MySQL's table encoding is utf8_general_ci and shell locale is LANG=en_US.UTF-8.
I got the answer from this post: http://forums.mysql.com/read.php?167,243667,243695#msg-243695
The problem is with MySQL++. After creating the connection, we need to execute:
mysqlpp::Query query = connection->query("SET NAMES 'utf8'");
query.execute();
Got this problem , error #1283, column cannot be part of FULLTEXT index. when changing collation from latin_swedish, to utf8_general_ci. Changed all manually but there are two columns on the Mysql table it is not changing but showing above error.
OK, I tried the PHP script to run, but truly again, where to execute it? is it to run from within the PHPmyadmin as the SQL query? or where?
Help, please.
Thanks.
I'm using PHP to suck up a CSV file, massage the data, and then import it into a MySQL InnoDB table using PDO.
The table and all varchar columns have a utf8_unicode_ci collation, and are utf8.
I have a column that is varchar(1).
When I attempt using PDO to do a certain query, I'm getting SQLSTATE 22001 Data too long for column 'HeatingOption' at row 1 error.
The query is as follows:
INSERT INTO `Config`.`BaseItemCodes`
(`BaseItemCode`, `Series`, `HeatingOption`, `StandardColor`)
VALUES ('BD1896-1W', 'BD18', 'w', 'BG')
It's interesting to me, because I'm debugging, and having PDO print out the query to the CLI. I copy/pasted the query, without modification, directly into MySQL Workbench and executed it just fine.
I'm currently creating the value from extracting it from the end of the BaseItemCode there. I'm using substr(), trim()ing it, and strtolower()ing it as well, just to make sure of everything.
The PHP script is utf8 w/o BOM, and so is the CSV file.
I'm on Windows 8.1 using PHP 5.5.7, and running MySQL 5.6.15 on a CentOS server.
I'm thinking it's some strange charset issue, but I'm not sure what to look at next.
Edit: I just attempted to change the column to 'char(1)' and it didn't help.
Edit 2: I increased the length of the column to varchar(20) and I was able to insert the data.
I'm changing my question to "Why do MySQL and PDO behave this way?"
Edit:
I double checked the data after inserting the row and increasing the length of the column, and it seems the name of the bind :HeatingOption was being passed through. So PDO wasn't binding the data for some reason, yet to be discovered.
the error clearly said it,
you should go to your database and change the lenth of that column HeatingOption to more then 1 , put it forexample varchar(25)
EDIT:
it should work with VARCHAR(1) or CHAR(1) however you may inserted spaces with this letter
example 'w '
^---//this spaces will be counted as bite, and it will be too long
I did research on this question and nothing I've read in the MySQL manual, in MySQL bug reports, in Stack Overflow, or in other forums has helped so far.
I have a simple mysql select query:
SELECT * FROM `Toyota` WHERE `Toyota`.`CollisionEstimatingID` = '22028589';
This query fails with mysql error code 1054
Unknown column Toyota.CollisionEstimatingID in the WHERE clause
This column DOES exist, I've checked the spelling of the database, table and column at least 30 times now. I even deleted my database and reimported. I have tried it with the backticks and without backticks, with alias' and without alias' I've tried it with explicitly named table.column syntax, and without the explicit syntax, I've tried mixing and matching all the stuff I've mentioned (backticks on the table, but not the column, on the column but not the table name), and nothing seems to work. It fails when I execute it from the mysql CLI on Ubuntu 12.04, it fails from my PHP 5.3 code, and it fails inside of phpMyAdmin. I am ready to flip a table.
When I try this though:
SELECT * FROM `Toyota`;
This works without any problems? Good god, MySQL is such a tease...
Here is the table setup as derived from show create database Toyota;
CREATE TABLE `Toyota` (
`CollisionEstimatingID` varchar(255) DEFAULT NULL,
`OE_part_number` varchar(255) DEFAULT NULL,
`Price` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
An interesting note -- I wonder if it could be character encoding problems? I did get it to work ONCE in phpMyAdmin by using the show create table Toyota and deleting everything but the "CollisionEstimatingID" and used that to form the SELECT statement. But when I tried cutting and pasting, no dice.
I tried recreating the database and tables using the utf8 character set to see if that would help, but it didn't help. I tried copying to text out of the phpMyAdmin window and into my source code -- that produced some funky characters at the beginning of the column name -- kinda like this: >>?CollisionEstimatingID only it was an 'i' with an umlaut + a double right chevron and an upside down question mark.
I'm stumped. Anyone want to test their programming mettle and help a brother out?
Like ""?
This is the UTF-8 BOM (en.wikipedia.org/wiki/Byte_order_mark).
You probably need to clean the input files first.
Your codes doesn't have any problem as i have did some testing with my SQL Server.
May be try this
SELECT * FROM Toyota WHERE Toyota.CollisionEstimatingID = '22028589'
Ok this is a new one for me. Basically I have a table articles:
id: int auto increment
title: varchar(200)
description: varchar(1000)
ctext: longtext
chtml: longtext
Now I do an insert into this table with mysql_query:
INSERT INTO articles
(title, description, ctext, chtml)
VALUES
('$title', '$description', '$text', '$html')
All values have been passed through mysql_escape_string().
The text and html here are roughly 50k in size (so I can't really post the fully query here).
Now, here's the problem: the query works. A new row is inserted. However the ctext and chtml columns are empty. This is MySQL 5.0.51a and PHP 5.2.8. No errors are raised of any kind as far as I can tell.
Now I dumped the query out to a file in /tmp and ran it with:
mysql -u username -p dbname < /tmp/query
Same thing.
I copy the query into Navicat and it... works.
So what on earth is going on?
Some random thoughts:
Have you tried controlling the text length see if it only fails at one point?
What kind of connection are you opening? Which driver?
Have you checked the encoding of your connection? Some invalid characters might be sent in.
Have you tried using parameters instead of mysql_escape_string?
Have you tried executing directly from the same file from Navicat instead of using the copy-paste? Again, might be related to an invalid character that's not passed through the copy-paste but was saved in the file.
Just to cover the basics we so often forget, how do you verify that the data is not inserted? I mean, how to you visualize it? You could have a line break that hides the first lines from 2 out of 3 means of visualization. Just a long shot, but I've seen it happen.
Addition: MySQL connections defaults to latin1, you need to use something like mysql_query("SET NAMES 'utf8'") to transfer unicode characters.
I'm not sure if this matters, but mysql_escape_string is deprecated and replaced by mysql_real_escape_string
Have you tried it with smaller text?