Archive for the ‘php’ Category

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.

How To Check If Array Element Exists In Another Array In PHP

This is the best 1 liner answer I found in the Internet to check if an array’s item or value or however you may call it exists in another array.

Using the function array_intersect(), you can achieve this. User lorenzo-s from Stack Overflow gave this 1 liner code that did the trick.

Do note that array_intersect() is case sensitive.

How To Fix Deprecated: Function eregi_replace() is deprecated In PHP

Well, if it says it is deprecated it does not work that it does not work anymore. Just that PHP advises developers to steer away from deprecated code and/or functions and use the new ones.

However, if you are still motivated to use the eregi_replace() function even though it is deprectead, just add @ to it so that the warning message for this will not appear.

Remember, just add @. So it will be @eregi_replace().

Related Posts Plugin for WordPress, Blogger...