当前位置:网站首页>MySQL数据库‘反斜杠\’ ,‘单引号‘’,‘双引号“’,‘null’无法存储
MySQL数据库‘反斜杠\’ ,‘单引号‘’,‘双引号“’,‘null’无法存储
2022-07-31 22:15:00 【小苗吃不够】
MySQL数据库‘反斜杠\’ ,‘单引号’'’,‘双引号""’,‘null’无法存储,\ ’ " null 字符被过滤
问题原因:
在mysql中这些字符被当做成了转义字符(单引号,双引号,反斜杠,null);
比如我们在写SQL语句时不管是查询修改还是新增,比如是一些文字或者数字都可以正常的进行查询和新增等,但是如果一旦里边包含了特殊字符,比如说要插入“今天下雨了\今天没下雨” 这里的反斜杠会被当成转义字符稀释掉,到了数据库内就是“今天下雨了今天没下雨”,这里类似于过滤掉了一样;
解决方式:
PHP addcslashes()函数
该函数要求PHP版本4+
addcslashes() //函数返回在预定义的字符前添加反斜杠的字符串。
//提示:该函数可用于为存储在数据库中的字符串以及数据库查询语句准备合适的字符串。
预定义字符是:
单引号(')
双引号(")
反斜杠(\)
NULL
该函数会对这些预定义字符前添加反斜杠\
$name = '小红\小蓝';
$name = addcslashes($name);
//这里的name值为 小红\\小蓝
//在数据库存储时第一个 \ 被当做转义字符
这个时候存储就不会有问题了;
将插入到mysql内的字符进行转义的实质是:将php中的特殊字符如(‘’,“”,, null)插入到数据库。
边栏推荐
- Student management system on the first day: complete login PyQt5 + MySQL5.8 exit the operation logic
- BM5 merge k sorted linked lists
- 顺序表的实现
- LevelSequence source code analysis
- Document management and tools in the development process
- The old music player WinAmp released version 5.9 RC1: migrated to VS 2019, completely rebuilt, compatible with Win11
- 财务盈利、偿债能力指标
- Redis综述篇:与面试官彻夜长谈Redis缓存、持久化、淘汰机制、哨兵、集群底层原理!...
- Golang - from entry to abandonment
- 架构实战营模块 8 作业
猜你喜欢
The article you worked so hard to write may not be your original
Daily practice——Randomly generate an integer between 1-100 and see how many times you can guess.Requirements: The number of guesses cannot exceed 7 times, and after each guess, it will prompt "bigger"
AI 自动写代码插件 Copilot(副驾驶员)
Bionic caterpillar robot source code
Pytest初体验
ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...
高效并发:Synchornized的锁优化详解
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
[Code Hoof Set Novice Village 600 Questions] Leading to the combination of formulas and programs
Architecture Battalion Module 8 Homework
随机推荐
sqlite3简单操作
Implementing a Simple Framework for Managing Object Information Using Reflection
Basic configuration of OSPFv3
Chapter Six
The old music player WinAmp released version 5.9 RC1: migrated to VS 2019, completely rebuilt, compatible with Win11
NVIDIA已经开始测试AD106和AD107 GPU核心的显卡产品
[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array
返回一个零长度的数组或者空的集合,不要返回null
C程序设计-方法与实践(清华大学出版社)习题解析
Unity-通过预制件和克隆方法动态实现各个UGUI下控件的创建和显示
Several methods for deleting specified elements in Golang slices
BM5 合并k个已排序的链表
STM32 full series development firmware installation guide under Arduino framework
Flink_CDC construction and simple use
【核心概念】图像分类和目标检测中的正负样本划分以及架构理解
Unity - by casting and cloning method dynamic control under various UGUI create and display
The principle of ReentrantLock (to be continued)
AI 自动写代码插件 Copilot(副驾驶员)
顺序表的实现
Memblaze released the first enterprise-grade SSD based on long-lasting particles. What is the new value behind it?