I just read about PHP Data Object(PDO) and found it really interesting and useful, so I decided to share this with everyone.
Introduction to PDO: Would not it be great if there were some way to write your code more abstractly, so that when you write a code for fetching data from database ? It would be smart enough to detect what type of database you are trying to connect to? That’s what PHP Data Object(PDO) attempts to do. PDO is an extension to PHP core library. It provides a data-abstraction layer so that you can use same set of functions to interact with database irrespective of the type of database you are using. Requirement: |
Using PDO: // Creating PDO Object // Write a query // and finally Once you have executed a SQL query the result will be stored in PDOStatement object($stmt in this case). You can get the values using fetch and fetchAll method on PDOStatement object. There are some predefined CONSTANT to assist you in getting the values in different formats. |