Now I would like to insert symbols to my MySQL table
I've spent a few hours over the net searching for an answer but I might be stupid or not because I could not find what I wanted
Now I insert my data to the database using command line
How can I insert symbols like "#;#,%,$,&,',..." into the table
Table collation is set to UTF8_unicode_CI
command I use
INSERT INTO table (name) VALUES ( "Assassin's Creed® 3" )
Now it shows up as
AssassinтАЩs Creed┬о 3
your query is right only the way you show it u must use htmlentities() or htmlspecialchars()
This first function is identical to
htmlspecialchars() in all ways, except
with htmlentities(), all characters
which have HTML character entity
equivalents are translated into these
entities.
ex: echo htmlspecialchars($row['name']) ;
be sure to pass values to mysql by mysql_real_escape_string() to avoid any SQL Injection problems.
Related
I've got a SQL operation with the word "şalom" which contains a non-ASCII character.
And the statement ( which I posted below ) runs totally fine:
UPDATE `myTable1` SET `description`='The topic for this learning plan starts with the \"ÅŸ\" ( sh ) letter which is a non-ASCII char. ', `topic`='ÅŸalom'' WHERE `RecID` = '1308'"
however, right after this statement, I have to run another one to put the word "şalom" in another table but that one FAILS. The reported error is follows:
INSERT INTO `myTable2` (`TOPIC_Name`, `TOPIC_AddedOn`) VALUES ('[Åÿalom]', '2018-04-12').
LAST SQL ERROR:
HY000, 1366, Incorrect string value: '\xC5\xFFalom...' for column 'Topic_Name' at row 1
We've checked the table structures and the field structures and saw that they are identical and designed to accept utf-8.
We cannot figure out why one statement passes but the other one chokes. Any ideas?
ÅŸ is Mojibake for ş. When treated as latin1, ÅŸ is hex C5FF. See Trouble with UTF-8 characters; what I see is not what I stored for discussion of "Best practice" and "Mojibake".
Trying to run this query -
INSERT INTO rmedvedeva993#gmail.com (url,unix)
VALUES (#https://youtu.be/xXsuqrhD8pw,#1500152563.66077);
after reading about this issue tried wrapping database like this- rmedvedeva993#gmail.com
getting an 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 '://youtu.be/xXsuqrhD8pw,#1500152563.66077)' at line 1
not quite sure what's the issue here,
P.S.: my columns are formated as char(255)
`
#hhttps://youtu.be/xXsuqrhD8pw and #1500152563.66077 aren't valid.
Neither is an email address as the name of a table. If you MUST use an email address as a table name, enclose it in backticks. But think long and hard about why you're doing that, then don't do it.
You probably want VALUES ('https://youtu.be/xXsuqrhD8pw',1500152563.66077); .
The # symbol in MySQL's dialect of structured query language denotes a user-defined variable. So you could have this:
#url := 'https://youtu.be/xXsuqrhD8pw';
#ts := 1500152563.66077;
INSERT INTO table (url,unix) VALUES (#url,#ts);
You need to quote your strings (whether char(xx), varchar(xx), or any other type which is represented as a string); and, when the names of your tables are not just letters and numbers, you have to quote them with the backtick quote: `. You most probably don't won't either the # symbol.
INSERT INTO `rmedvedeva993#gmail.com` (url,unix)
VALUES ('https://youtu.be/xXsuqrhD8pw','1500152563.66077');
Side Note: Is your table really named rmedvedeva993#gmail.com? Can you post your table definitions (use SHOW CREATE TABLE table_name).
I'm creating a log table which logs actions that affect the database, and I store the sql statements in a field called details.
Below is an example query where I try to insert a row into my log table but I run into problems with the details part, as I am inserting a query into the field and mysql interprets it as part of the actual query and errors
INSERT INTO `user_log` SET `log_dts`='2012-05-28 15:07:19', `user_id`='4', `details`='UPDATE `property` SET `timedeleted` = '2012-05-28 15:07:19' WHERE `propertyid` IN (1594930)'
How is it best to handle this?
Thanks.
edit: to add, the details field is a text field in the mysql db.
You need to escape the quotation marks in your string.
See: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html
You have to add an escape character to the "'", just replace all occurrences of ' in the query with \'.
mysql_real_escape_string - d'uh
I'm doing this directly in the mysql client. I want to do the following:
INSERT INTO MYTABLE VALUES(1,12,'\u5c40\u5c42');
So it would insert the two unicode characters. I'd like to do this without using some other programming language if possible, I'd like to just paste my insert statements right into mysql client.
What's the type of your table data? char or varchar? Your issue isn't quite clear, are you getting an error from that line? You might be experiencing: http://dev.hubspot.com/bid/7049/MySQL-and-Unicode-Three-Gotchas.
EDIT:
Quite a bit of information is within these three pages that should be able to help:
http://dev.mysql.com/doc/refman/5.5/en/charset-unicode.html
http://dev.mysql.com/doc/refman/5.5/en/string-syntax.html
http://dev.mysql.com/doc/refman/5.5/en/charset-literal.html
but I also saw this :
INSERT INTO mytable VALUES (1, 12, _ucs2'\x5C40\x5C42');
Using the mysql console, I can just paste your unicode characters into an insert command and mysql accepts it. Here's a little test I did using your data:
CREATE TABLE xx (col1 varchar(20));
insert into xx values ('局层');
select * from xx;
+---------+
| col1 |
+---------+
| 局层 |
+---------+
My db uses default encoding (latin1).
Have you tried just pasting them in? What error, if any, do you get?
It will depend on what you are programming with or if just dealing with the database directly. Are you just trying to do a straight insert from querybrowser or some other tool or are you doing this via a web app. IF the second, what language is the webapp using. If it is a .net app you can try setting the character set in the connection string i.e. charset=utf8
If you are doing something with php then take a look at this link http://randomchaos.com/documents/?source=php_and_unicode
You could also go and set the default character set on the database to UTF-8. Not sure how this will impact the current data so be sure to backup everything before making changes to the database.
By using MySQL Workbench
Alter the table of that column you want to insert unicode into.
Change Collation of that column to utf8-default collation.
Apply the setting and you are good to go to insert unicode.
In my case, I needed to insert Arabic characters into MySql server through C# form application. The only way that worked for me is as follows:
First: In your code, specify character set in the connection string as follows:
MySqlConnection mysqlConn = new MySqlConnection("Server= serverName; Port=3306; Database= dbName; Uid = userName; Pwd=password; charset=utf8");
Second: In phpMyAdmin console, click on your database name link, then head to "operations" tab and go to "Collation" at the bottom and select "utf8_unicode_ci" and check the options below and finally click on "Go"
Steps here
this worked for me
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Change character set to utf8
mysqli_set_charset($con,"utf8");
I have a php script that inserts values into mySQL table
INSERT INTO stories (title) VALUES('$_REQUEST[title]);
I checked the values of my request variables before going into the table and it's fine.
But when I add title=john to the table for example,
I get something like this:
title = "[][][][]john"
and when I extract the value, it's a newline then john.
I have my columns set to utf-8, I tried swedish character set as well.
Note: I don't get this error when inserting values from the phpMyAdmin commandline
You need {} around any array notation when used inside "".
$q="INSERT INTO stories(title) VALUES('{$_REQUEST['title']}')";
BTW, it would be better, when checking your $_REQUEST vars to store the sanitized versions in new variables, and to be sure to escape them with real_escape_string()
SET NAMES <encoding> query must be executed every time you connect to your database.
very simple rule.
where <encoding> is your HTML page encoding in mysql dialect (utf8 for the utf-8)
You need to check the character set of the database, the server, and the client.
Note that it's not a swedish character set, it's a swedish collation.