简体   繁体   中英

save special character in mysql ® ? php

i am having a problem with updating my msyql with this sentence :

davc® 50PCS 

when i run the bellow query in mysql workbench it works:

UPDATE products 
SET 
    title = 'davc® 50PCS '
WHERE
    product_id = '386'

but when i run the same query from my server ,it succeed to run but it delete every thing after ® .

i think i should do something with encoding ? i am using php and mysqli object.

thanks

https://stackoverflow.com/a/38363567/1766831 discusses both problems that you encountered:

  • "Truncation", which is usually caused by the text being latin1, but trying to store into utf8 (or utf8mb4).
  • "Mojibake" (such as â® ), which is again caused by the text and column disagreeing. But it also involves the connection parameters not agreeing with the encoding in the client.

Something like this

$text = utf8_encode ( "davc® 50PCS " );

UPDATE products SET 
title = "{$text}" WHERE product_id = '386'

Important: change your sql to secure it from sql injections. Something like this: http://www.w3schools.com/php/php_mysql_prepared_statements.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM