Which Is Better In PHP: PDO Or MySQLi?

I am not sure if this is a matter of one’s preference but I believe from my experience PDO provides more coding flexibility that MySQLi.

Here is an example so you will better understand what I mean.

Now, if that were to be MySQLi, I would be doing it like this:

Notice the difference? I had to call if conditions twice. If my query is very long, then my code would also be long.

Plus, there is also the issue of mysqli_escape_string(). With PDO, you do not have to call one since it calls that function automatically when you bind values to the parameters.

When I started using prepared statements in MySQL because of the SQL injection issue, this is the main reason why I opted to use PDO rather than MySQLi.

Found this useful? Donations appreciated to help keep this blog alive.

Toggle 1 And 0 Values In An Update MySQL Statement

Good thing MySQL has the IF() function that enables us to update a column by switching values to 0 if current value is 1 and vice versa in just 1 query.

This way, we do not have to waste resources by querying for the current value and then executing an update query.

Found this useful? Donations appreciated to help keep this blog alive.

Related Posts Plugin for WordPress, Blogger...