64

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.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
  • 15
    MYSQL is deprecated from 5.5 and its fully removed in PHP 7 .. There are MYSQLi and PDO libs to connect mysql.. 2-3 years was the period for moving all old apps into the new None MYSQL way.. – Svetoslav Dec 04 '15 at 12:26
  • In the migration document, it tells you that `mysql_` is removed. Also, entire SO is screaming about this removal for several years now. There are no such functions any more and you can't use them. If your project depends on it, revert back to php version that supports it. – Mjh Dec 04 '15 at 12:33
  • I think you need to read and digest the PHP7 [release notes](http://php.net/ChangeLog-7.php#7.0.0) and also the [Migration notes](http://php.net/migration70) Before attempting any move to PHP7. Its a very different beast now – RiggsFolly Dec 04 '15 at 12:36
  • [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. – Jay Blanchard Dec 04 '15 at 13:30
  • 3
    Why all the down-votes? This guy asked a reasonable question, and got a reasonable answe! – Jan Steinman Dec 22 '15 at 23:39
  • 2
    You can manually install the mysql extension and it works with PHP7 - see https://github.com/php/pecl-database-mysql – David Goodwin Apr 22 '16 at 08:45
  • What @JanSteinman said. I simply didn't know mysql_ was deprecated, because I'm way behind as far as PHP goes. – bytecode77 Jun 21 '16 at 14:56

1 Answers1

88

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');
Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20