Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PDO vs MySQLi

Posted on 2015-01-14
4
Medium Priority
?
664 Views
Last Modified: 2015-01-15
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
Comment
Question by:APD_Toronto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 total points
ID: 40550408
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
 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 1000 total points
ID: 40550434
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
 

Author Comment

by:APD_Toronto
ID: 40551874
By the way, is it true that MySQLi does not use named parameters?
0
 
LVL 34

Expert Comment

by:Slick812
ID: 40552091
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question