如何将特殊字符插入数据库?
问题描述:
任何人都可以告诉我如何在MySQL数据库中插入特殊字符?我做了一个PHP脚本,这意味着插入一些单词到数据库,虽然如果该单词包含一个',那么它不会被插入。
Can anyone tell me how to insert special characters into a MySQL database? I've made a PHP script which is meant to insert some words into a database, although if the word contains a ' then it wont be inserted.
我可以在使用PHPmyAdmin时插入特殊字符,但是在通过PHP插入它们时它不起作用。难道是PHP正在将特殊字符改变成别的东西吗?如果是这样,有没有办法使它们正确插入?
I can insert the special characters fine when using PHPmyAdmin, but it just doesn't work when inserting them via PHP. Could it be that PHP is changing the special characters into something else? If so, is there a way to make them insert properly?
答
$insert_data = mysql_real_escape_string($input_data);
假设您将数据存储为 $ input_data