Page 247 - Open Soource Technologies 304.indd
P. 247
Unit 10: Database
10.3.3 When not to use a database abstraction layer? Notes
The biggest downside of using a database abstraction layer is that the benefits come at a
performance cost. Imagine you were planning to travel around Europe and had the choice of
bringing an interpreter who could speak all European languages and learning the languages
yourself. It would certainly be easier to bring the interpreter, but this would make each
conversation you had somewhat slower. The abstraction layer is the interpreter.
10.3.4 Using PEAR DB
The connection string for connecting to the database with PEAR DB is:
Syntax
driver://username:password@host/database
Some of the drivers supported by PEAR DB are:
• mysqli
• mysql
• mssql
• oci8
• odbc
• pgsql
• sybase
• dbase
• sqlite
10.3.5 Code Sample: PEAR-DB/Demos/EmployeeReport.php
<html>
<head>
<title>Employee Report</title>
</head>
<body>
<?php
require_once ‘DB.php’;
@$DB = DB::connect(‘mysqli://root:pwdpwd@localhost/Northwind’);
if (DB::isError($DB))
{
echo ‘Cannot connect to database: ‘ . $DB->getMessage();
}
else
{
$Query = ‘SELECT * FROM Employees’;
LOVELY PROFESSIONAL UNIVERSITY 241