将字符串插入到MySQL中

编程入门 行业动态 更新时间:2024-10-22 20:40:28
本文介绍了将字符串插入到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中

本文发布于:2023-07-31 08:40:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1257255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!