Home > Backend Development > PHP Problem > What should I do if the backslash is not added when php is imported into the database?

What should I do if the backslash is not added when php is imported into the database?

藏色散人
Release: 2023-03-15 07:14:01
Original
1821 people have browsed it

php入库时没有加反斜杠的解决办法:1、打开相应的代码文件;2、通过“addcslashes($detail,"\\");”方法将反斜杠进行转义即可。

What should I do if the backslash is not added when php is imported into the database?

本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑

php 入库时没有加 反斜杠怎么办?

PHP 数据中的反斜杠插入数据库后消失了

原因就是:

反斜杠(\ )需要进行转义。

列入:

INSERT INTO `stu` VALUES('lisi',   'school\class\stu_num',  '188/900');
Copy after login

这样直接插入数据库不行

所以用了addcslashes();

例如:

$deatil = addcslashes($detail,"\\");
INSERT INTO `stu` VALUES("$name",   "$detail",  "$else");
Copy after login

另外想到了magic_quotes_gpc 函数,所以提一下:

这个特性在PHP5.3.0中已经废弃并且在5.4.0中已经移除了(This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.)。所以没有理由再使用魔术引号,因为它不再是 PHP 支持的一部分。 不过它帮助了新手在不知不觉中写出了更好(更安全)的代码。 但是在处理代码的时候,最好是更改你的代码而不是依赖于魔术引号的开启。

推荐学习:《PHP视频教程

The above is the detailed content of What should I do if the backslash is not added when php is imported into the database?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template