Solved

PDO vs MySQLi

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php construct 5 26
Is there a limit to how many inner joins you should use? 4 30
PHP populating an array. 4 23
Is there a simpler dropbox system? 10 18
This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
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 …

785 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