当前位置:网站首页>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)插入到数据库。
边栏推荐
- A high-quality WordPress download site template theme developed abroad
- C#中引用类型的变量做为参数在方法调用时加不加 ref 关键字的不同之处
- 「APIO2010」巡逻 题解
- The difference between adding or not adding the ref keyword when a variable of reference type is used as a parameter in a method call in C#
- 「SDOI2016」征途 题解
- Embedded development has no passion, is it normal?
- BM3 将链表中的节点每k个一组翻转
- AI automatic code writing plugin Copilot (co-pilot)
- Bionic caterpillar robot source code
- Pytest初体验
猜你喜欢

老牌音乐播放器 WinAmp 发布 5.9 RC1 版:迁移到 VS 2019 完全重建,兼容 Win11

Payment module implementation

useragent online lookup

The article you worked so hard to write may not be your original

Redis Overview: Talk to the interviewer all night long about Redis caching, persistence, elimination mechanism, sentinel, and the underlying principles of clusters!...

Getting Started with Tkinter

Financial profitability and solvency indicators

A shortcut to search for specific character content in idea

TestCafeSummary

Realization of character makeup
随机推荐
Basic configuration of OSPFv3
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
MATLAB program design and application 2.4 Common internal functions of MATLAB
Summary of the classic drawing method of histogram
Learn about C# anonymous methods
ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...
BM5 合并k个已排序的链表
Unity-LineRenderer显示一条线
sqlite3 simple operation
求n以内的素数
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"
Audio alignment using cross-correlation
cas and spin locks (is lightweight locks spin locks)
Go1.18 upgrade function - Fuzz test from scratch in Go language
focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
登录业务实现(单点登录+微信扫码+短信服务)
Carbon教程之 基本语法入门大全 (教程)
Student management system on the first day: complete login PyQt5 + MySQL5.8 exit the operation logic
A solution to the server encountered an internal error that prevented it from fulfilling this request [easy to understand]
C language parsing json string (json object is converted to string)