tags:

views:

2044

answers:

5

Which is better? Mysl or mysqli? And why? Which should I use?

Better - not just in terms of performance, but any other relevant features.

Thanks

+1  A: 

What is better is PDO; it's a less crufty interface and also provides the same features as MySQLi.

Using prepared statements is good because it eliminates SQL injection possibilities; using server-side prepared statements is bad because it increases the number of round-trips.

MarkR
+3  A: 

MySQLi stands for MySQL improved. It's an object-oriented interface to the MySQL bindings which makes things easier to use. It also offers support for prepared statements (which are very useful). If you're on PHP 5 use MySQLi.

Ross
+6  A: 

If you have a look at MySQL Improved Extension Overview it should tell you everything you want to know about the differences.

Then main useful things are Object-oriented interface, Support for Prepared Statements, Support for Multiple Statements, Support for Transactions, Enhanced debugging capabilities and Embedded server support.

Mark Davidson
+1  A: 

for me, prepared statements is a must-have feature. more exactly, parameter binding (which only works on prepared statements). it's the only really sane way to insert strings into SQL commands. i really don't trust the 'escaping' functions. the DB connection is a binary protocol, why use an ASCII-limited sub-protocol for parameters?

Javier
PDO usually uses client-side prepared statements, so they aren't really prepared on the server - but this is good, as it saves server resources and usually performs better. The prepared statement "emulation" will always escape things correctly.
MarkR
"always" and "escaping" are dangerous words when go together. i don't know, maybe this code is totally bug-free; but why bother, when a real binary protocol is available? as for performance, that's open to benchmarking.
Javier
+3  A: 

I have abandoned using mysqli. It is simply too unstable. I've had queries that crash PHP using mysqli but work just fine with the mysql package. Also mysqli crashes on LONGTEXT columns. This bug has been raised in various forms since at least 2005 and remains broken. I'd honestly like to use prepared statements but mysqli just isn't reliable enough (and noone seems to bother fixing it). If you really want prepared statements go with PDO.

cletus
PDO isn't exactly perfect either (I've run in to some nasty coredumps with it), but at least it has a wider userbase, so it's probably a safer bet.
troelskn