Pregunta

I have developed an open source PHP application and currently it uses both the MySQLi or MySQL extension for backwards compatibility. I'm wondering about switching it over to only be compatible with MySQLi since PHP now no longer supports the MySQL. Another reason I'd like to get away from supporting both MySQL and MySQLi is that I'm basically using MySQLi the same way I do as with the old MySQL extension. Can anyone explain to me if this is a good or bad idea?

¿Fue útil?

Solución

If you are going to switch anyway, you should really consider going with PDO instead of MySQLi.

The main benefit, would be that your application would be able to work with any of the 11 other database backends supported by PDO, with minimal fuss. This might not be a priority for you, but since this is an open source application there's little reason to not try and make it as flexible as possible. Also, you'd be able to use named parameters in your prepared statements (MySQLi supports prepared statements, but not named parameters).

In any case, moving away from the mysql_* functions is a very good idea. These days, it's just a relic of the (dark) past, and unless backwards compatibility is an inescapable requirement there's absolutely no reason to use it.

Otros consejos

The preferred method is to use only mysqli. As you said, the older MySQL extension is no longer supported. Both can connect to most versions of MySQL server, so there's no reason at all to use the old extension.

In terms of performance, mysqli is better, if your intended users are solely mysql based, then use mysqli else you can try PDO which will give you the flexibility of connecting to other databases with minimal changes.

I think PDO is slightly slower due to that fact that its more generic compared to mysqli or oci, but that is nothing to worry about.

You can create 2 scripts, one with PDO, the other with Mysqli and you apache ab to benchmark. With my test Mysqli was slightly faster in terms of request processed as compared to PDO but I must admit was negligible.

Licenciado bajo: CC-BY-SA con atribución
scroll top