Viewers: in countries Watching now:
Now that PHP has true object-oriented capabilities, it's best practice to access databases using PDO (PHP Data Objects) and MySQLi. These methods produce database-neutral code that works with over a dozen systems, including MySQL, SQL Server, PostgreSQL, and SQLite. Learn how to use PDO and MySQLi to perform basic select, insert, update, and delete operations; improve security with prepared statements; and use transactions to execute multiple queries simultaneously. Author David Powers also covers advanced topics like instantiating custom objects, and compares PDO to MySQLi so you can decide which method is right for you.
Both PDO and MySQLi have support for transactions. A transaction, is a set of SQL queries that's executed as a single unit. Changes are committed to the database, only if each part of the transaction is successful. If an error occurs at any stage during the transaction, you can roll back each record, to its original value. This is particularly useful for operations such as financial transfers, where it's vital that all parts of the transaction succeed.
Another advantage, is that all parts of a transaction are grouped into a single execution unit that locks records to prevent them from being modified by another connection. If you're using MySQL or MariaDB as your database, data must be stored using the InnoDB engine on MySQL or XtraDB on MariaDB. Some commands can't be rolled back. This mainly affects SQL statements such as drop, alter and create.
That define the structure of tables and databases. You can't use transactions with MyISAM tables. Neither PDO nor MySQLi ,issue a warning if you try to do so. They simply ignore rollback commands. MyISAM, was the default storage engine, prior to MySQL 5.5. So you might need to convert your tables, if you want to use transactions. If you're not sure how to convert a table from MyISAM to NODB, check out chapter five of my course, Up and Running with phpMyAdmin here on lynda.com
There are currently no FAQs about Accessing Databases with Object-Oriented PHP.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.