You??™ll still use persistent connections to improve the efficiency of opening a new
database connection for each client request.
This solution is the one you will use for data access in the TShirtShop project.
Using PHP PDO for Database Operations
Now, we??™ll talk about how to put this in practice??”opening and closing database connections
and executing queries using those connections??”using PHP PDO.
As explained in Chapter 2, you won??™t access MySQL through PHP??™s MySQL extension functions,
but through a database abstraction layer (PHP PDO). The PDO classes permit accessing
various data sources using the same application programming interface (API), so you won??™t
need to change the PHP data access code or learn different data-access techniques when
working with database systems other than MySQL (but you might need to change the SQL
code itself if the database you migrate to uses a different dialect). Using PHP PDO is the modern
way to interact with your database, and it makes your life as a programmer easier in the long run.
The important PHP PDO class you??™ll work with is PDO, which provides methods for performing
various database operations. We can take advantage of the many methods already in the
PDO class to process data, make connections to the DB, and for many other common tasks;
we are spared having to write the code for these common tasks, because they are already
included in the PDO class.
Pages:
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167