Solved

PDO vs MySQLi

Posted on 2015-01-14
4
589 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
  • 2
4 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 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 33

Assisted Solution

by:Slick812
Slick812 earned 250 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 33

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now