New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

The multi-platform PDO interface

From: MySQL Essential Training

Video: The multi-platform PDO interface

This is the CRUD application. I've written CRUD in PHP, using the PDO interface for database operations. So, in the case of MYSQL, this block of code here will be, executed

The multi-platform PDO interface

This is the CRUD application. CRUD stands for, create, read, update, and delete, the four basic functions of any database application. I've written CRUD in PHP, using the PDO interface for database operations. PDO is PHP data objects, a cross platform database interface for PHP. PDO provides a consistent interface for different database engines, allowing application like CRUD to support SQLite.

Post and SQL, and MYSQL with minimal changes. Scrolling down here a little bit, you'll notice at the top, there are three different blocks of constants, and one of them is in commented, and the other ones are commented out. If I were would, comment this one and uncomment one of the other ones, this same. Code would work with a different database engine. Post SQL, SQL white three or MySQL as in the case here.

Here in text wrangler i can simply select a PHP function and it'll, jump to it in the code. This is the emit function you'll notice at the top of the code, after I initialize all of theses constants and variables, I call emit first and then I call main. And main is simply a jumping off point for, whatever is requested of the function, which is based on web buttons like, I push anywhere on the page. The emit function is called, first though.

And it sets up the database connections. It sets up the, various variables, it initializes things. It gets the application ready to run. And you'll notice down here in init, I have this switch statement, based on DB-Engine. And DB-Engine is defined up at the top here as MySQL. So, in the case of MYSQL, this block of code here will be, executed and this is a tri block, which is how, exceptions are handled in PHP.

And, the first thing it does, is it creates a new PDO object. The PDO interface is object oriented. So, a connection is made by creating a new PDO object. The, $dbh variable, is a traditional is a traditional name for this. It stands for database handle. It's archaic, but it's very common. And it will hold, the PDO object. The connection string, which is this string right here between these quotes. This is called a DSN which stands for data source name.

Its database specific. Notice that the format, is different for each of the different. Database systems. Here you can see for postgress it's different. It includes a port number and, a database name. And, you notice for SQLite it just includes the, database file. The DSN is followed by the user name and password, which is followed by driver options. ATTR persistent, which is the persistent attribute option, provide support for persistent connection.

This means that an instance of this script can remain connected with the server for multiple passes, eliminating some of the overhead of, reestablishing a new connection every time the script is called. PHP offers a number of different interfaces to support MySQL. For a new code, I strong recommend the PDO interface. It's well-maintained. It's efficient. It's object oriented. And it supports MySQL well, as well as most of the, major database management systems.

Show transcript

This video is part of

Image for MySQL Essential Training
MySQL Essential Training

60 video lessons · 4682 viewers

Bill Weinman

Expand all | Collapse all
  1. 4m 22s
    1. Welcome
      1m 3s
    2. Using the exercise files
      1m 31s
    3. What is MySQL?
      1m 48s
  2. 45m 37s
    1. Installation overview
      3m 16s
    2. Installing XAMPP on Windows
      5m 55s
    3. Installing XAMPP on the Mac
      6m 38s
    4. Setting up MySQL users
      11m 31s
    5. Installing SID on Windows
      5m 43s
    6. Installing SID on the Mac
      6m 6s
    7. Installing time zone support in MySQL on Windows
      6m 28s
  3. 45m 43s
    1. The SELECT statement
      3m 57s
    2. Selecting rows
      4m 57s
    3. Selecting columns
      3m 8s
    4. Sorting results with ORDER BY
      2m 58s
    5. Filtering results with WHERE
      3m 52s
    6. Filtering results with LIKE and IN
      3m 41s
    7. Filtering results with regular expressions
      8m 21s
    8. Inserting rows
      4m 9s
    9. Updating rows
      2m 21s
    10. Deleting rows
      2m 25s
    11. Literal strings
      3m 12s
    12. Understanding NULL
      2m 42s
  4. 41m 47s
    1. Creating a database
      4m 30s
    2. Creating a table
      7m 18s
    3. Creating indexes
      6m 8s
    4. Controlling column behavior with constraints
      4m 46s
    5. Creating an ID column
      6m 58s
    6. Using foreign key constraints
      7m 58s
    7. Altering a table
      4m 9s
  5. 28m 56s
    1. What are data types?
      4m 1s
    2. Numeric types
      5m 21s
    3. String types
      2m 58s
    4. Date and time types
      7m 2s
    5. Bit type
      2m 26s
    6. Boolean values
      2m 15s
    7. Enumeration types
      4m 53s
  6. 32m 34s
    1. String functions
      6m 57s
    2. Numeric functions
      6m 2s
    3. Date and time functions
      4m 12s
    4. Time zones in MySQL
      3m 37s
    5. Formatting dates
      1m 51s
    6. Aggregate functions
      5m 45s
    7. Flow control with CASE
      4m 10s
  7. 7m 6s
    1. Maintaining database integrity with transactions
      4m 46s
    2. Using transactions for performance
      2m 20s
  8. 16m 49s
    1. Updating a table with a trigger
      5m 11s
    2. Preventing automatic updates with a trigger
      7m 29s
    3. Logging transactions with a trigger
      4m 9s
  9. 14m 11s
    1. Creating a simple subselect
      3m 23s
    2. Searching within a result set
      3m 53s
    3. Creating a view
      3m 32s
    4. Creating a joined view
      3m 23s
  10. 12m 26s
    1. Understanding MySQL stored routines
      2m 0s
    2. Creating a stored function
      4m 34s
    3. Creating a stored procedure
      5m 52s
  11. 14m 4s
    1. The multi-platform PDO interface
      3m 44s
    2. Executing the SQL
      4m 8s
    3. Implementing auto-increment IDs
      2m 3s
    4. Using a stored funciton
      4m 9s
  12. 1m 3s
    1. Goodbye
      1m 3s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes changes my life forever. @JosefShutter
@lynda is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?


Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from

Sign up and receive emails about and our online training library:

Here’s our privacy policy with more details about how we handle your information.

submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.