mysql_real_escape_string 未定义 [英] mysql_real_escape_string is undefined

查看:34
本文介绍了mysql_real_escape_string 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP 5.3 版并尝试在我的代码中使用 mysql_real_escape_string($unescaped_string),但出现错误:

I am using PHP version 5.3 and trying to use mysql_real_escape_string($unescaped_string) in my code, but I get the error:

Fatal error: Call to undefined function mysql_real_escape_string() 
in /var/www/engine/database.php on line 38

但是我仍然可以连接到数据库.为什么不可用?

I can still connect to the database however. Why is it not available?

我使用的是 PHP 5.3 版.

I am using PHP version 5.3.

推荐答案

更新评论mysql_自 5.5 起已弃用:

自 PHP 5.5 起不推荐使用 mysql 扩展.应改用 mysqli 或 PDO 扩展.已在 mysql_deprecation 中决定弃用,其中可以找到有关此决定背后原因的讨论.

The mysql extension has been deprecated since PHP 5.5. The mysqli or PDO extension should be used instead. The deprecation has been decided in mysql_deprecation, where a discussion of the reasons behind this decision can be found.

并且在 PHP 7 中移除.

mysql_real_escape_string()MySQL 函数批处理"的标准部分" 并且在正确加载扩展程序的情况下应该始终有效.

mysql_real_escape_string() is standard part of MySQL function "batch" and should always work if the extension is loaded correctly.

还有其他 mysql_ 函数可以工作吗?(应该不会)

Does any another mysql_ function work? (It should not)

确保在 php.ini 中取消注释此行:

Make sure, that you have this line uncommented in your php.ini:

extension=mysql.so

此外,使用 mysqliPDO 代替(mysql_ 已弃用),它们都可以为您解决转义问题.

Also it'd be wise to use mysqli or PDO instead (mysql_ is deprecated), they both can take care of escaping for you.

这篇关于mysql_real_escape_string 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆