php Codeigniter 已弃用:mysql_real_escape_string():

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31808703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:37:53  来源:igfitidea点击:

Codeigniter Deprecated: mysql_real_escape_string():

phpmysqlcodeignitermysql-real-escape-string

提问by Sofiya

Got below error while using codigniter 3.0

使用 codigniter 3.0 时出现以下错误

FYI using PHP Version 5.5.12,Apache Version Apache/2.4.9 (Win64) PHP/5.5.12

A PHP Error was encountered

Severity: 8192

Message: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

Filename: models/common_model.php

Line Number: 21

Backtrace:

File: C:\wamp\www\Codeigniter\application\models\common_model.php Line: 21 Function: mysql_real_escape_string

遇到 PHP 错误

严重性:8192

消息:mysql_real_escape_string():不推荐使用 mysql 扩展并将在将来删除:改用 mysqli 或 PDO

文件名:models/common_model.php

行号:21

回溯:

文件:C:\wamp\www\Codeigniter\application\models\common_model.php 行:21 功能:mysql_real_escape_string

回答by Aniket Singh

use mysqli_real_escape_string();

mysqli_real_escape_string();

and replace mysqlto mysqliin every functions.

并在每个功能中替换mysqlmysqli

回答by Hassaan

Go to application => config => database.phpand change from

转到application => config => database.php和更改自

$db['default']['dbdriver'] = 'mysql';

to

$db['default']['dbdriver'] = 'mysqli';

NoteIt is recommended to use query builder classfor queries.

注意建议使用查询构建器类进行查询。

回答by Aniket Singh

You should use PDO in codeigniter to solve all problem related to mysqland mysqli..

您应该在 codeigniter 中使用 PDO 来解决mysqlmysqli..

see how to use PDO in CI if you are using CI 3 then http://www.codeigniter.com/user_guide/database/configuration.html

如果您使用的是 CI 3,请查看如何在 CI 中使用 PDO,然后http://www.codeigniter.com/user_guide/database/configuration.html

and if you are using CI 2.x How to use pdo in codeigniter?

如果您使用的是 CI 2.x 如何在 codeigniter 中使用 pdo?