PHP is a scripting language that is commonly used on amateur web sites.
The primary use of PHP is to draw data from a database and display it on a web page.
PHP became very popular because it was made available on discount web hosts and was good enough to get the job done.
The program was poorly designed and the database driver was subject to "SQL injection" hacks.
PHP removed its buggy database connection with a convoluted pseudo object called PDO which destroys the flow of PHP program and effectively destroys PHP. The database connection should be a function, not an pseudo-object.
(Note, in PHP, one uses the "function" and procedure interchangeably)
Before I start my rant I would like reader to take a second and think about a URL such as "www.example.com/test.html?x=1" . The URL starts with a host name followed by a path. Sometimes URLs include a question mark followed by a list of parameters.
An HTML form has the same design. The data in the form is stuck in the HTTP header and sent to a site.
When you type in a URL or click on a web form, you send a block of data to a server.
The server sees a resource name and a block of data.
Every single web call has the same form. It is the name of a resource and a block of data.
In programming a "procedure" is a named programming structure that takes with a discrete parameter than then processes the data given in the parameter. (A "function" is a procedure that returns an output.)
The very structure of the World Wide Web indicates that traditional procedural programming is the best way to program web sites.
In junior college the professoriat teaches that there is a higher level of thinking called "object oriented programming."
In computer lingo an object is an abstract construct that includes a group of procedures and related data.
Your professor probably taught that OOP caused a "paradigm shift" and that programmers should develop all programs as objects.
That is bull-honky.
The stinking word "paradigm" usually does nothing more than indicate that the person speaking is a pretentious snit.
The structure of the system one is working on should determine programming style and not the musings of some misinformed professor in a junior college.
Please at the Internet. Every resource on the wWW is referenced by a URL. A URL has a path, a name of a resource and parameters. The strucure of the Internet is best represented with procedural programming.
Anyway, in 1979 a Danish programmer named Bjarne Stroustrup created the programming language C++. The language attempted to achieve ideals of object oriented programming with a program structure called a class. A class includes functions and data variables.
In C++ programmers put their classes in a hierachy.
The Windows operating that we all know and hate was built around the class hierarchies created in C++ and it is a bloated mess.
Anyway, the deverlopers at Zend were sitting in a programming class at the junior college when the professor said the majic word that "Object Oriented Programming" is a "paradigm shift." Because it is a paradigm shift, all computer programs must be forced to use the hierarchical class structure that was introduced in C++.
This is bogus. Every URL is a named resource with an optional set of parameters that is either in the URL itself or the HTTP header.
The best path for web programming is a procedure.
I know what you are thinking. If the professor at the junior college said that there was a "paradigm shift" shouldn't we all ignore the structure of the real world and follow the stinking new paradigm?
Anyway, PHP was a kludgy language from the beginning. The decision to replace their database connection with a pseudo-object turned it into something awful.
So, I've been stuck in a rut. As far as I am concerned, when PHP replaced its database connection with a pseudo object, they effectively destroyed their language.
What I've done for existing code is to create two procedures that encapsulate the PDO object.
I called my first function dbConn(). This function holds an array of PDO objects. This way I can access multiple types of databases.
I then created three functions "sqlValue()", "sqlRow()" and "sqlAll()". The first returns a single value, the second a row and the third returns an entire result set as an array. The function sqlExec() will execute DML commands like UPDATE, INSERT, etc..
I put the code I use for these functions on my web site
I want to create an open source program. The database connection used by PHP (PDO) makes me feel ill.
So, before I write open source code, I have to explain why I don't use PDO.
In conclusion, the programming paradigm used in your code should be driven by the structure of the overall system you are using. One the World Wide Web, every resource is identified by a URL. A URL has a path, a resource name and additional parameters attached with a question mark or in the HTTP header.
This means that traditional procedural programming is the best structure for most web pages. PHP gained market share because, despite its buggy database connection, it allowed straight forward procedural programming.
I am not adverse to object-oriented design. The PDO pseudo object does not lend itself to true object oriented design.
Were I to develop an enterprise application, I would never in a million years use the PHP pseudo object. Creating an object-oriented web site is beyond this this thread.
I want to write an open source program. I will create the prototype using PHP, SQLite3. I will use the functions I displayed on this page that encapsulate the PDO object.
I am tempted to skip PHP altogether and just write the stupid thing in C.
Because Zend has done such a bad job with its database connection, I no longer recommend using PHP.