EllisLab text mark
Advanced Search
1 of 2
1
   
Why no PDO?
Posted: 30 January 2011 06:15 AM   [ Ignore ]
Joined: 2010-08-31
51 posts

I’m not an expert, so that’s why I’m asking.

Why don’t CI’s database functions use PDO?  I did some research on database security, and over and over read that the best way to fortify the database is to use parameterization.

 
Posted: 30 January 2011 02:03 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2010-08-31
51 posts

Ok, besides the theoretical why, should I implement PDO in my site, or can I trust CI’s security?

 
Posted: 30 January 2011 03:41 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-06
743 posts

If you use active record or query binding you are safe since CI uses mysql_real_escape_string() to guard against sql injection. Parameterized queries are similar to CI’s query bindings. The advantage to parameterized queries on databases that support them is speed when executing the same query but with different data multiple times. Think multiple inserts. PDO supports parameterized queries on databases that support them, but PDO can also emulate parameterized queries which is the same thing as CI’s query binding.

 Signature 

“I am the terror that flaps in the night”

 
Posted: 05 February 2011 01:01 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-08-15
154 posts

Have a look at http://www.phpactiverecord.org/

 
Posted: 05 February 2011 06:28 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-08-31
51 posts

Thanks JonoB, PHP Active Record looks awesome.

Rick Jolly, I understand that it does, but this site and others like it are what led me to think that that wasn’t good enough.

http://bobby-tables.com/

There is only one way to avoid [injection] attacks

  * Do not create SQL statements that include outside data.
  * Use parameterized SQL calls.

That’s it. Don’t try to escape invalid characters. Don’t try to do it yourself. Learn how to use parameterized statements. Always, every single time.

The strip gets one thing crucially wrong. The answer is not to “sanitize your database inputs” yourself. It is prone to error.

 
Posted: 05 February 2011 09:43 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-06
743 posts

ispod, rest assured that mysql_real_escape_string() is completely safe. If it wasn’t, most php applications would be vulnerable to sql injection attack.

Of course, we developers can screw anything up when we don’t know what we are doing.

 Signature 

“I am the terror that flaps in the night”

 
Posted: 05 February 2011 11:38 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-08-31
51 posts

Ok, thank you, that’s great to know!  I’m satisfied with DMZ and glad to not have to change ORM’s for security reasons.

 
Posted: 08 February 2011 07:42 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2011-02-08
3 posts

Its a good question ! Why there are plenty of files for the DB instead of use the fast and very very simple to use ....

All the time I do a new CI projet, I remove all the DB files and add my small PDO wrapper ...

 
Posted: 21 April 2011 06:09 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2006-04-23
96 posts
eBuildy - 08 February 2011 12:42 PM

Its a good question ! Why there are plenty of files for the DB instead of use the fast and very very simple to use ....

All the time I do a new CI projet, I remove all the DB files and add my small PDO wrapper ...

could you share your PDO wrapper ?

thinking about using Pdo in new project so would like to know if exists any PDO library/driver for CI 2.x or have to create my own from the scratch ?

was trying to find but i cant :\

 
Posted: 23 April 2011 03:31 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-23
9 posts

I don’t understand why’d you use the PDO. CI protects you. But you know, there is a filter system in CI too. And you can always use PHP’s Sanitize Filters as well.

 Signature 

-
crag

 
Posted: 23 April 2011 03:39 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-23
9 posts
ipsod - 05 February 2011 11:28 PM

Thanks JonoB, PHP Active Record looks awesome.

Rick Jolly, I understand that it does, but this site and others like it are what led me to think that that wasn’t good enough.

http://bobby-tables.com/

There is only one way to avoid [injection] attacks

  * Do not create SQL statements that include outside data.
  * Use parameterized SQL calls.

That’s it. Don’t try to escape invalid characters. Don’t try to do it yourself. Learn how to use parameterized statements. Always, every single time.

The strip gets one thing crucially wrong. The answer is not to “sanitize your database inputs” yourself. It is prone to error.

With the PDO you can bind your vars/fields. But you dont have to. It’s extra work especially with big forms. But it is worth the time. But you still should sanitize your data. PHP provides some nice tools for that (there’s a link in my post above).

It is not hard to protect your site from a SQL Injection attack. You just can’t be lazy. Every form, every page a user can type data must be sanitized.

And CI does it all for you, if you want. Easy peasy.

 Signature 

-
crag

 
Posted: 23 April 2011 04:39 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2006-04-23
96 posts
Crag - 23 April 2011 07:31 AM

I don’t understand why’d you use the PDO. CI protects you. But you know, there is a filter system in CI too. And you can always use PHP’s Sanitize Filters as well.

exists small thing - customer wants PDO to be used - this should be the answer to the WHY smile

 
Posted: 23 April 2011 05:21 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-23
9 posts
EugeneS - 23 April 2011 08:39 AM
Crag - 23 April 2011 07:31 AM

I don’t understand why’d you use the PDO. CI protects you. But you know, there is a filter system in CI too. And you can always use PHP’s Sanitize Filters as well.

exists small thing - customer wants PDO to be used - this should be the answer to the WHY smile

Ok. Good enough for me. wink

 Signature 

-
crag

 
Posted: 23 April 2011 06:55 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2008-12-14
544 posts
EugeneS - 23 April 2011 08:39 AM

exists small thing - customer wants PDO to be used - this should be the answer to the WHY smile

Customer has no clue what PDO is.

 
Posted: 24 April 2011 12:06 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

Besides if you want PDO then write a driver for it and the database stuff!

InsiteFX

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 16 May 2011 10:38 PM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Joined: 2010-07-11
1 posts
Rick Jolly - 06 February 2011 02:43 AM

ispod, rest assured that mysql_real_escape_string() is completely safe. If it wasn’t, most php applications would be vulnerable to sql injection attack.

Of course, we developers can screw anything up when we don’t know what we are doing.

I’m sorry, but this is bad advice. Parameterization is much safer than escaping query strings. Abstraction and security are the main reasons for the use of PDO. Performance is nothing but a side effect. If you want to improve query performance, you use sensible indexes and stored procedures (and beyond that sharding, clustering, etc.)

mysql_real_escape_string does very little to prevent injection attacks.

 
1 of 2
1