PHP currently offers multiple ways of working with MySQL. Some of the more popular methods include:
PEAR (PHP Extension and Application Repository) DB package
This package offers a database-independent API for communicating with relational databases from PHP. PEAR::DB includes support for MySQL, but provides only rudimentary support for MySQL stored programs.
PHP MySQL extension (ext/mysql)
This PHP extension provides MySQL-specific support for working with MySQL. However, the mysql extension does not include methods for working with advanced MySQL features introduced in MySQL 4.1 and 5.0 and will probably never provide direct support for stored programs.
mysqli interface (ext/mysqli)
This PHP extension was introduced to support new features in MySQL 4.1 and 5.0.
PDO (PHP Data Objects)
PDO is a database-independent interface that will probably become the successor to the PEAR::DB interface. PDO became an officially supported interface only in PHP 5.1, so it is the newest of the PHP database interfaces.
Only the mysqli and PDO extensions provide full support for MySQL stored programs. In this chapter we will show how each can be used to interface with MySQL and how to use MySQL stored programs.
Part I: Stored Programming Fundamentals
Introduction to MySQL Stored Programs
MySQL Stored Programming Tutorial
Blocks, Conditional Statements, and Iterative Programming
Using SQL in Stored Programming
Part II: Stored Program Construction
Creating and Maintaining Stored Programs
MySQL Built-in Functions
Part III: Using MySQL Stored Programs in Applications
Using MySQL Stored Programs in Applications
Using MySQL Stored Programs with PHP
Using MySQL Stored Programs with Java
Using MySQL Stored Programs with Perl
Using MySQL Stored Programs with Python
Using MySQL Stored Programs with .NET
Part IV: Optimizing Stored Programs
Stored Program Security
Tuning Stored Programs and Their SQL
Basic SQL Tuning
Advanced SQL Tuning
Optimizing Stored Program Code
Best Practices in MySQL Stored Program Development