将字符串插入到MySQL中 [英] Inserting strings into MySQL

查看:139
本文介绍了将字符串插入到MySQL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我认为我在MySQL中的insert语句弄乱了输入数据库的字符串。



我有一个insert语句,如这在PHP代码中:

  $ sql ='insert into my_table(numeric_id,string_value)
values('。$ some_number。',''。$ some_text。')';

此后,我得到 $ some_text 从数据库中,它混淆了像
don \'t 这样的字符串,而不是像 \r\\ \\ n 到输出。



任何想法为什么会发生这种情况,我应该改变什么?

解决方案

你的某些代码正在执行两次转义。

你只需要找到第二次执行代码即可摆脱它。 / p>

首先你必须打印出你的变量才能看到它的实际内容。

很难理解被盲目的事物,并且基于假设



只需打印出 $ some_text 变量,然后再转义并查看。如果它已经被转义了,那么在代码中的某个地方进行额外的转义。


I am running into a problem where I think my insert statement in MySQL is messing up the strings that get entered into the database.

I have an insert statement like this in PHP code:

$sql = 'insert into my_table ( numeric_id , string_value ) 
        values ( '.$some_number.' , "'.$some_text.'" )';

And when later I get the $some_text from the database, it messes up strings like don\'t instead of don't and ads things like \r\n to the output.

Any idea why this is happening and what I should change?

解决方案

Some of your code is doing escaping twice.
You just have to find the code that does it second time and get rid of it.

first of all you have to print out your variables to see it's actual contents.
It's hard as hell to sort out things being blinded and based on assumptions.

Just print out $some_text variable before escaping it and see. if it's already escaped - then additional escaping been done somewhere earlier in the code.

这篇关于将字符串插入到MySQL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆