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
Codeigniter Deprecated: mysql_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 mysql
to mysqli
in every functions.
并在每个功能中替换mysql
为mysqli
。
回答by Hassaan
Go to application => config => database.php
and 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 mysql
and mysqli
..
您应该在 codeigniter 中使用 PDO 来解决mysql
与mysqli
..
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?