奇怪而烦人的错误:调用未定义函数mysql_query() [英] Wierd and Annoying error: Call to undefined function mysql_query()

查看:538
本文介绍了奇怪而烦人的错误:调用未定义函数mysql_query()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里呆了一个多小时,我可以连接到我的数据库以及所有数据库(不给出任何错误),但是当我尝试使用时出现以下错误 "mysql_query($ query);"

I've been at this for more than an hour now, I can connect to my database and all (doesn't give any errors) but i get the following error when i try to use "mysql_query($query);"

Call to undefined function mysql_query()

我已经尝试启用:

extension=php_mysql.dll
extension=php_mysqli.dll

我已经添加:

extension_dir = "ext"
extension=php_mysql.dll

在导入列表的末尾.

在我进行的每一次更改之间,我都重新启动了exsappp中的所有进程,而在我分别尝试过的每个解决方案之后,它仍然给出了这个令人讨厌的错误.

Between every change I made I restarted all processes in exampp and after every single solution that I seperately tried it still gives this annoying error.

我尝试过在线查找,但唯一类似于我的错误是:

I've tried looking online, but the only error similar to mine would be:

Call to undefined function mysql_connect()

我从来没有遇到过任何问题,从未见过.

which at no point I've have had any issue with, never seen it.

我在这里问这个问题,是因为我在Google搜索结果中收到了上述问题的垃圾邮件;不是我所拥有的那个.

I'm asking it here because I am being spammed on the google search results with the problem above; Not the one I am having.

如果有人可以帮助我,我将非常感激,我在网上找到的教程可以显示与我编写的完全相同的代码.

I would be greatful if someone could help me with this, the tutorials I've found online show the exact same code that I have written.

推荐答案

PHP 7放弃了mysql_query(),因为它以多种方式存在问题!该API并不鼓励良好做法,官方的说法是它没有维护,也没有任何准备声明!从本质上讲,这是PHP中最大的问题,它会导致导致sql注入的不良做法,并且这是一个主要的严重不良情况.

PHP 7 has gotten rid of mysql_query() because it's problematic in a variety of ways! The API does not encourage good practices, the official line is that it's unmaintained, and NO PREPARED STATEMENTS!?! It essentially is the biggest problem in PHP that encourages bad practices leading to sql injection, and that's a major big bad situation.

但是,我确实使用旧版代码库,因此在某些情况下,我必须处理与您相同的情况.如果您的代码库很小,则只需更新数据库连接方法即可.如果您的代码库很大,那么我建议您这样做:

However, I do work with legacy codebases, so I have to deal with the same situation as you in some cases. If you have a small codebase, just update your db connection method. If you have a large codebase, here is what I recommend:

  • 将此代码库的php版本回滚到php 5.6,它将在2016年获得更多支持.
  • 请花一些时间更新到PDO(您可以创建一个 围绕PDO进行包装,以使其不再那么冗长,并且仍然允许准备 查询).
  • 忽略mysqli.如果从mysql_ *升级花费5分钟,则可能是做错了,让自己对sql-injection开放.只需进行PDO并开始使用准备好的查询,这样您就可以在晚上睡觉.
  • 如果您仍然想在更现代的项目中使用php 7,请在其上使用旧的php 5.6旧版代码库启动一个容器实例.
  • Rollback your php version for this codebase to php 5.6, it will be supported for a bit more of 2016.
  • Take your time to update to PDO (you can create a wrapper around PDO to make it less verbose and still allow prepared queries).
  • Ignore mysqli. If it takes you 5 minutes to upgrade from mysql_*, you are probably doing it wrong, and leaving yourself open to sql-injection. Just go for PDO and start using prepared queries so you can sleep at night.
  • If you still want to use php 7 in more modern projects, spin up a container instance with the older php 5.6 legacy codebases on it.

这篇关于奇怪而烦人的错误:调用未定义函数mysql_query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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