当前位置:网站首页>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)插入到数据库。
边栏推荐
- focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
- Linux environment redis cluster to build "recommended collection"
- [Intensive reading of the paper] iNeRF
- Collation of knowledge points in Ningbo University NBU IT project management final exam
- renderjs usage in uni-app
- 【AcWing】The 62nd Weekly Match 【2022.07.30】
- The principle of ReentrantLock (to be continued)
- The latest masterpiece!Alibaba just released the interview reference guide (Taishan version), I just brushed it for 29 days
- 「APIO2010」巡逻 题解
- Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
猜你喜欢
Federated Learning: Multi-source Knowledge Graph Embedding in Federated Scenarios
基于STM32 环形队列来实现串口接收数据
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
Recognize anomalies (you will understand after reading this)
[NLP] What is the memory of the model!
The article you worked so hard to write may not be your original
How to identify fake reptiles?
Quick Start Tutorial for flyway
MATLAB program design and application 2.4 Common internal functions of MATLAB
一款国外开发的高质量WordPress下载站模板主题
随机推荐
Mobile web development 02
A solution to the server encountered an internal error that prevented it from fulfilling this request [easy to understand]
MATLAB program design and application 2.4 Common internal functions of MATLAB
支付模块实现
UVM RAL model and built-in seq
21. Support Vector Machine - Introduction to Kernel Functions
What's wrong with the sql syntax in my sql
嵌入式开发没有激情了,正常吗?
Shell script quick start to actual combat -02
"SDOI2016" Journey Problem Solution
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
The latest masterpiece!Alibaba just released the interview reference guide (Taishan version), I just brushed it for 29 days
uni-app中的renderjs使用
server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none failed
Chapter VII
Bika LIMS open source LIMS set - use of SENAITE (detection process)
老牌音乐播放器 WinAmp 发布 5.9 RC1 版:迁移到 VS 2019 完全重建,兼容 Win11
利用反射实现一个管理对象信息的简单框架
Thymeleaf是什么?该如何使用。
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用