Solved

PDO vs MySQLi

Posted on 2015-01-14
4
596 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

21 Experts available now in Live!

Get 1:1 Help Now