Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 676
  • Last Modified:

PDO vs MySQLi

HI Experts,

I am currently in the process of starting a large PHP application, and I am wondering which is newer /more recommended, PDO or MySQLi? I find MySQLi easier, especially with its OO approach. Which is the newest and more professional?

As well, I keep reading that in PHP you do not have to destroy objects as it automatically does at the end of the script, is this true?

What about $result->free(); to close the recordset and $db->close() to close the db connection, $statement->close() to close the statement and free up memory.

Thank you,
0
APD Toronto
Asked:
APD Toronto
  • 2
2 Solutions
 
Ray PaseurCommented:
Well, that would best be expressed in three questions, not one, but I'll try to answer.

PDO or MySLQi: This is a "holy war" question.  Which one do you know better?  Use that one!  We choose PDO when we cannot force a client into a particular database engine.  It's a choice for the designers of frameworks -- not you.  Just pick up whatever you're comfortable with.

PHP garbage collection: Yes, this works "out of the box" and you do not have to think about it.  Sometimes PHP gets it right!

PHP $result->free() and $db->close(): Recommend you experiment with it.  Probably you will not need these at all.
0
 
Slick812Commented:
Greetings APD_Toronto, , I have used both mysqli and PDO, and I would say that they both work. HOWEVER, the PDO is a complicated "wrapper" to use several many different databases. I NEVER use PDO, if I can avoid it, even in the latest version it will default to using NON prepare and execute code to a MySQL database, EVEN THOUGH you call the Mysql, an use the  PDO prepare and execute in your code, in the under code it will substitute the NON prepare SQL string, and just write the normal SQL, and automatically escape the variables. Test this out and you will see that, at least it does it on the servers I use, even with PHP 5.5.
So use mysqli if you have any choice about it.

  Also, in SQLite and PostgreSQL, PDO does NOT subsittute the normal SQL for the prepare and execute code, there's some setting in the PDO the sets it to do the Non  Referenced in Mysql
0
 
APD TorontoAuthor Commented:
By the way, is it true that MySQLi does not use named parameters?
0
 
Slick812Commented:
Short answer to your question - "Yes" - - - - -

I will assume you are talking about using a prepare SQL string and then using "place holders" for the INPUT Data, and then Binding the Variables to the place holders.
mysqli is set up to bind all variables to "place holders" In ONE STEP, as just One method, , the  bind_param( ) method.
So as far as I know, or have seen, you MUST use the question mark   ?   for a place holder, and therefore NO text symbols (named parameters)  like   :param1  are allowed.

you can see examples here -
    http://php.net/manual/en/mysqli-stmt.bind-param.php
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now