Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Re-introducing PDO – the Right Way to Access Databases in PHP
Aug 25, 2015 @ 16:10:14

On the SitePoint PHP blog they have a post that "reintroduces PDO" or as they describe it, the "right way to access databases in PHP". The PDO functionality in PHP provides extra handling around database connections and queries as well as making it easier to connect to multiple types of databases with similar code.

PDO is the acronym of PHP Data Objects. As the name implies, this extension gives you the ability to interact with your database through objects. [...] PHP is rapidly growing, and it is moving toward becoming a better programming language. Usually, when this happens in a dynamic language, the language increases its strictness in order to allow programmers to write enterprise applications with peace of mind.

In case of PHP, better PHP means object-oriented PHP. This means the more you get to use objects, the better you can test your code, write reusable components, and, usually, increase your salary. Using PDO is the first step in making the database layer of your application object-oriented and reusable.

He starts by answering the question most ask about PDO versus mysql/mysqli by pointing out that PDO is more OOP friendly, it allows for parameter binding and the fact that the mysql extension is no longer supported. He shows how to check and ensure PDO is installed on your setup and, if not, how to add it in (for both linux and Windows systems). The tutorial then walks you through using PDO: making the connections to the server, running queries and returning the results. This includes a section on prepared statements and bound parameters and their benefits including SQL injection prevention.

tagged: pdo database access tutorial introduction prepared statements phpdataobjects

Link: http://www.sitepoint.com/re-introducing-pdo-the-right-way-to-access-databases-in-php/

Chad Lung's Blog:
A quick intro to using PHP PDO with MySQL
Mar 17, 2011 @ 14:52:55

Chad Lung has posted an introduction to PDO, PHP Data Objects, in a simple PHP script:

PHP PDO (PHP Data Objects) ship with PHP 5.1 and above and is very easy to work with. Today I'm going to show you one way of performing CRUD actions on a MySQL database using PDO. Keep in mind what I'll show you is only one way of doing things and just a fraction of what PDO can do.

He shows how to connect it to your MySQL database (via the connect string) and, based on his sample "pdo-demo.users" table, use prepared statements to insert and select data into/out of the table. There's a full code listing at the end showing a comprehensive view of each of the types - select, insert, update and delete.

tagged: pdo mysql tutorial introduction phpdataobjects

Link:

Lukas Smith's Blog:
Let's think PDO!
Oct 26, 2009 @ 15:32:03

Lukas Smith has formally kicked off a restart of the PDO (PHP Data Objects) abstraction layer, trying to get interest back into this part of the PHP project and get developers back into patching and creating more features on it as a whole.

The problem with PDO's current state is that there are just so many bugs open that it seems like a maintain. Plus the original creator(s) are busy with other things, which means the learning curve is steep. Which makes it all the more important that we both have new guys as well as experienced core developers on this. I think for too long we have waited for RDBMS vendors to bring in the momentum. However since we decided to not play according to the "rules" they have proposed, its obviously our job and not theirs.

He asks that all that are interested in closing out those bugs and really getting the development of PDO back on track sign up for the mailing list and check out the brainstorming page on the PHP wiki on general ideas and thoughts on where the project should be headed.

tagged: pdo phpdataobjects restart interest

Link:


Trending Topics: