Prev | Current Page 75 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

1 and is offered as a PECL extension for PHP 5.0 (PECL is a repository of
PHP extensions, located at http://pecl.php.net/). The official PDO manual, together with
installation instructions, is available at http://php.net/pdo.
CHAPTER 2 ?–  LAYING OUT THE FOUNDATIONS 23
PDO offers a uniform way to access a variety of data sources. Using PDO increases your
application??™s portability and flexibility, because if the back-end database changes, the effects
on your data-access code are kept to aminimum (in many cases, all that needs to change is
the connection string for the new database).
After you become familiar with the PDO data-access abstraction layer, you can use the same
programming techniques on other projects that might require a different database solution.
To demonstrate the difference between accessing the database using the old PHP functions
and PDO, let??™s take a quick look at two short PHP code snippets.
?– Note If you aren??™t familiar with how the code works, don??™t worry??”we??™ll analyze everything in greater
detail in the following chapters.
The following shows database access using PHP native (MySQL-specific) functions:
// Connecting to MySQL
$link = mysql_connect('localhost', $username, $password);
if (!$link)
{
die ('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tshirtshop', $link);
if (!$db_selected)
{
die ('Could not select database : ' .


Pages:
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
Pozycjonowanie imprezy integracyjne warszawa Odżywki obrączki ślubne kraków kreator www