"Call to undefined function mysql_connect()" after upgrade to php-7

bytecode77 picture bytecode77 · Dec 4, 2015 · Viewed 203.7k times · Source

After I upgraded php5 to php7, I get an error 500 with

PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect()

I put this into my apt sources in order to get php7 right now:

deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all

What I basically did is:

apt-get remove php5
apt-get install php7-*

I'm using the current version of Debian Jessie.

But I still get this. There are a lot of questions here on SO and I definitely checked them all out. But I didn't find an answer there yet.

Answer

Abhishek Sharma picture Abhishek Sharma · Dec 4, 2015

From the PHP Manual:

Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide. Alternatives to this function include:

mysqli_connect()

PDO::__construct()

use MySQLi or PDO

<?php
$con = mysqli_connect('localhost', 'username', 'password', 'database');