php7 and mysql extension [duplicate]

2020-05-09 22:21发布

After launching the following code...

<?php
error_reporting(E_ALL);
mysql_connect()
?>

I have Uncaught Error: Call to undefined function mysql_connect() in log.

The first thing that comes in mind is to do sudo apt-get install php-mysql but it outputs

Reading package lists... Done
Building dependency tree
Reading state information... Done
php-mysql is already the newest version

after that I did dpkg --list | grep mysql and it said that php-mysql and php7.0-mysql are installed.

What is wrong here?

PS. PHP version is 7.0.8.

标签: php mysql
2条回答
我命由我不由天
2楼-- · 2020-05-09 23:08

You need to use the mysqli_* functions, not mysql_*.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-05-09 23:15

Call to undefined function mysql_connect

The mysql_ library was deprecated years ago. It has been removed entirely in PHP 7.

Use a modern replacement such as PDO or mysqli_.

查看更多
登录 后发表回答