mysql创建表时表明加单引号,将单引号添加到mysql结果中,有时但不总是

Initially when i try to add a string that have Single quotations the database used to return an error message..

So i added addslashes to that string before the query.

After adding the addslashes, the String looks like this in DataBase.

For some reason the backslashes are not always inserted.

3STIp.png

Please suggest me a method for handling quotes after going through this scenario

Case1: Using Addslashes

I already have a huge code, where if i use addslashes before insertion, i must also use stripslashes after select query to remove \ in every result. This will result lot of changes in my controllers and models IN Codeigniter.

Case2: Without addslashes

If i dont use addslashes or mysql_escape my database doesnot allow me to store single quotes.

I changed the charset to utf8mb4_general_ci, but still of no use..

I also made sure that the charset in config.php also contains utf8mb4 charset.

Any suggestions for an efficient method?

解决方案

I found the solution, hope this will be helpful to others

Update MySql to 5.5.3+ and use charset utf8mb4_general_ci.. Make sure

that the datatype is longtext

That's it. No need of using addslashes and stripslashes as far as i know.

It also supports emoji's

Thanks

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值