MySQL deprecated? Check out what to do

MySQL outdated

(Originally posted on my Portuguese blog at rberaldo.com.br)

Have you ever seen this error message?

PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

So, you might ask me…

Outdated MySQL? So, I can not use it anymore?!

Not exactly. We’re only talking about the mysql extension. And I’m going to show you exactly what to do to solve this issue and prevent your scripts from stopping working with PHP 7 (scheduled to be released by mid-December 2015).

The MySQL database management system (DBMS) is one of the most commonly used with the PHP language. A significant portion of popular systems made in PHP use (or at least support) the MySQL database.

Just like PHP, MySQL has evolved significantly and gained new features in recent years. This prompted the PHP development team to create a new library to work with these innovations more effectively. This new library was called MySQLi (with the “i” standing for “improved”).

Outdated MySQL vs. Outdated MySQL Extension

MySQL is the DBMS itself. I’m not exactly talking about MySQL. I’m talking about the mysql extension (or mysql library) of PHP.

The MySQL library, which includes functions like mysql_connect, mysql_query, and similar ones, does not allow the use of new MySQL features such as triggers, stored procedures, and more. These features are only available when using the MySQLi library.

The MySQLi extension has been available since PHP 5.0, released on July 13, 2004. Since then, it was recommended to use MySQLi instead of MySQL.

However, many programmers continued to use, and still use, the MySQL library.

To change this situation, the PHP team took a somewhat drastic step: they removed the MySQL library from PHP 7.

But don’t worry! Don’t panic!

Outdated MySQL Extension

Starting from PHP 5.5, the MySQL library is considered obsolete but still functional. However, it is recommended not to use it anymore, as it has already been removed from PHP 7, which is expected to be released by the end of 2015.

Was This a Drastic Move?

Many find it absurd that the PHP team made the MySQL library obsolete in PHP 5.5. But let’s analyze it further.

As I mentioned earlier, the MySQLi extension was launched with PHP 5.0 on July 13, 2004. Since then, the PHP community has been suggesting the use of this library instead of MySQL.

However, few programmers embraced the idea.

The PHP team’s conclusion: let’s force them to migrate to MySQLi.

Version 5.5.0 was released on June 20, 2013, which is NINE YEARS after the publication of PHP 5.0 and the recommendations for using MySQLi.

We are in 2015 (as I write this article), and there are still people using MySQL.

ELEVEN YEARS have passed! Throughout all this time, the PHP community has been suggesting the use of MySQLi.

So, I don’t find it at all drastic to make MySQL obsolete. After all, many people only act when they are “backed into a corner.”

So put laziness aside and migrate your applications to MySQLi or PDO right away!

What Should I Do, Beraldo?

Alternatives to the MySQL Extension

  1. Use the MySQLi extension instead of MySQL
  2. Use the PDO extension (PHP Data Object)

Which one should I choose, Beraldo?

The MySQLi extension will give you everything you already have with the MySQL extension today. Additionally, you will have access to the new MySQL features. You will also be using a more recent library.

But the PDO extension has a significant advantage.

PDO is a database abstraction layer. The name might sound intimidating, but it’s simple: it is a generic interface for various database management systems (SGBDs). This means that your code written with PDO will work with MySQL, PostgreSQL, SQLite, and various other SGBDs.

The advantage of this is that if you ever need to change the database management system, you will have to make very few changes to your code.

We never know what the future holds. Maybe your application will grow significantly and require a change of the database management system. So, if PHP already provides this feature as a bonus, it’s worth using it! ?

Here is a tutorial on how to use PDO with MySQL.

But I know that many beginners have difficulty with Object-Oriented Programming and may find PDO challenging. That’s why I created this article, where I show how to use MySQLi without needing to use Object-Oriented Programming.

Related posts

10 Thoughts to “MySQL deprecated? Check out what to do”

  1. SparK

    Velho… MySQL com php continua funcionando, são as funções da lib que são depreciadas!
    O título do post é só pra dar infarto no veio, né? Tou sabendo.

    1. Olá, SparK

      O título é: MySQL obsoleto: não utilize ***funções mysql_****

      Deixo claro que estou falando sobre funções mysql_*. E explico tudo no post. Caso tenha ficado alguma dúvida, pode perguntar.

      Abraço
      Beraldo

  2. tiominga

    Muito bem explicado, parabéns

      1. Pedro Pereira

        Òtimo post. Você podia indicar aí um bom curso online de PHP 7 ? Vlw

        1. Eu tenho um curso completo de PHP, o ULTIMATE PHP 2.0, incluindo as novidades do PHP 7. Dê uma olhada: http://www.ultimatephp.com.br/curso/

          1. Pedro Pereira

            Muito bacana o seu curso. Bem completo. Estou interessado em fazê-lo. Você pode me informar quanto custa e se tem certificado ?

            Em 25/09/2017 13:27, “Disqus” escreveu:

          2. Olá. O curso não possui certificado. Um certificado de PHP só é válido se for da Zend, como Zend Certified Engineer. Qualquer outro certificado de cursos que não são da Zend não possuem validade oficial. Quem oferece esses tipos de certificados simples está apenas iludindo o aluno

  3. Dilo Moura

    kkk “Muitos só se mexem quando a água bate na bunda..” kkk Fato!
    Brasileiros, sempre deixando as coisas pra última hora. rs
    Boníssimo post Beraldo, obrigado!

    1. haha é essa a verdade, infelizmente.
      Por isso eu sempre aconselho os iniciantes a já começaram com MySQLi ou PDO. Assim evitam essas dores de cabeça ?

Leave a Comment