TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-15-2010, 12:23 PM   #1 (permalink)
The Visitor
Newcomer 
 
Suhana's Avatar
 
Join Date: Dec 2009
Location: UK
Posts: 1
Thanks: 0
Suhana is on a distinguished road
Default To PDO or not?

Various discussions of late in a number of IRC channels has caused me to again examine the PDO interface however I am having difficulty in seeing what if any advantages there are over my current preference of the MySQLi interface.

Statements such as "you are using prepared statements of course?" are usually met on my side with a large dose of sighing .. and if I am foolish enough to ask the fatal "why?" the conversation deteriorates into a discussion about the pros and cons of preventing SQLi.

Now while I may only be a "fair" to "passable" programmer, I an more than fully aware of blocking this type of attack, which I hasten to add, I believe has nothing to do with SQL at all, and is simple a failure to sanitize user input correctly.

Again, with prepared statements there's the case for "well it's easier to use". Not sure I can agree with this. For one, he very fact of preparing a statement generates traffic to the database server unless I;m very much mistaken, and that in turn has the scope to kill one application I manage - which is already pushing my knowledge of scaling with MySQL.

Binding parameters? so:

Code:
INSERT INTO `table` (`f1`, `f2`, `f3`) VALUES (?, ?, ?)
followed by some lines of PHP to prepare, and bind the values is easier and/or more legible than a quick bit of sanitization of user input followed by:

Code:
$sql = sprintf("INSERT INTO `table` (`f1`, `f2`, `f3`) VALUES (NULL, %u, '%s')", $f2, $f3);
$res = mysql_query($sql, $conn);
Frankly, I'm not convinced. So what else does the PDO supply? OOPS - Well I favor procedural code however I do "nod" in the direction of classes and have sufficient strength in classes and the skill to link them correctly without issue.

Exceptions? Nothing really special here. Sure, I throw a few where I believe the application has reached a state that could cause a problem, and given the fact that there still appears to be some small unusual bugs in PDO, I'd rather use something that has a proven track record.

Speed? I've no idea on this one - if anybody has experience here on the comparison speed-wise between MySQL, MySQLi, and PDO/MySQL, I'd be delighted to see some benchmarks, comments etc.

"It's the done thing" Unfortunately I often hear this from people who run Windows servers, or small database - and by small I mean < 1 million rows. The MySQLi interface is for me handling 50 million rows without any headache, in a master/master (active/passive) + redundant r/o slave configuration.

"Using PDO makes it easy to change to different DBMS". Well that's a new one me. For one, I'd have to rewrite almost all queries, and probably a small chunk of the application to handle the differences, so sorry, but that argument fails.

So finally, I really have to ask: just why should I change to the PDO interface? What sort of problems am I liable to encounter? What sort of speed issues are there? Are there server-side issues I need to be aware off? (I already use mysql-proxy to permit certain tricks plus my applications are always read-write split aware).
Suhana is offline  
Reply With Quote
Old 01-15-2010, 01:59 PM   #2 (permalink)
The Wanderer
Newcomer 
 
Parvus's Avatar
 
Join Date: Aug 2008
Posts: 21
Thanks: 1
Parvus is on a distinguished road
Default

I've been sitting with this as well and the choice really is yours to make.

For benchmarks and extra info you might want to visit this link: *Click me*

Personally I have decided to switch from MySQL to PDO (instead of switching from MySQL to MySQLi) after reading a lot of different things on the web.
For me, the following points were the reason to go to PDO:
- MySQL will slowly go and PDO will be the new standard
- PDO is now standard in PHP and since it is pretty new, I'm convinced it will be improved
- If I need to change my database, it certainly will be easier with PDO and only a vew queries might have to be changed (since I use pretty standard queries)
- PDO is OOP and while it might not be a real argument for some people, I do like programming OOP above Procedural since a while now

*Some info I found may be false, if so, then I would like to hear this as well =]
- I like prepared statements above using mysql_real_escape_string() all the time
Parvus is offline  
Reply With Quote
Old 01-16-2010, 05:15 PM   #3 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

I looked into using PDO not too long ago for the Dingo Framework, but I quickly found that it did not meet my requirements.

In other words, I found that using PDO was not the right solution for what I was trying to do. Not saying PDO is bad, in fact it is quite good, but it is not a one-size fits all kind of deal. Like you said, PDO doesn't solve the issue of having to rewrite queries if you switch DBMS, which I believe is PDO's main failure.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 01-16-2010, 06:00 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
Like you said, PDO doesn't solve the issue of having to rewrite queries if you switch DBMS, which I believe is PDO's main failure.
That's not a shortcoming of PDO - PDO, as it states, is not a database abstraction layer, it's a data access abstraction. Using it as such is using a phillips to screw in a robertson.
delayedinsanity is offline  
Reply With Quote
Old 01-18-2010, 02:01 PM   #5 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

True, but PDO is supposed to make switching DBMS easier, right? If it doesn't handle the SQL part of the problem, then in my opinion it doesn't do the job. In order to easily switch DBMS you would have to write your own wrapper for PDO, which is the exact same thing I would have to do with MySQLi/PgSQL.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:52 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design