mysql_query段错误,奇怪而烦人的错误:调用未定义函数mysql_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()

I've already tried enabling:

extension=php_mysql.dll

extension=php_mysqli.dll

and I've added:

extension_dir = "ext"

extension=php_mysql.dll

at the end of the import list.

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.

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.

e106d543cfd13165e751fa36a02b6972.png

3qjwR.png

解决方案

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:

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.

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值