News Feed
Jobs Feed
Sections

Recent Jobs

News Archive
CodePoets.co.uk:
A Quickstart to using PEAR with PHP
April 13, 2006 @ 07:09:23

On CodePoets.co.uk today, a new tutorial introduces you to the PEAR DB package, giving you a howto guide on performing simple queries with its functionality.

PEAR::DB, provides a uniform, cross platform, cross database method for connecting to databases, when writing PHP applications/scripts. Extensive documentation can be found online here This article aims to show briefly, how queries and updates can be performed when using PEAR DB.

They list a few reasons why one might want to use the PEAR DB package over the normal PHP database functions before they get into the examples. There are four examples - making the connection, querying the database, what to do to avoid SQL injections, and updating your database with prepared statements.

1 comment voice your opinion now!
php pear db package quickstart howto connect query sql update php pear db package quickstart howto connect query sql update



Pear DB sucks
Using the Pear DB class is a bad idea. The overhead is just huge. Take a look at this example, creating csv output for a table containing 2427 records.

# Query once, so mysql query cache is not an issue
$DB->query("SELECT * FROM medewerker");

# ----------

$output1 = "";
$time = microtime(true);
$result_pear = $DB->query("SELECT * FROM medewerker");
while ($row = $result_pear->fetchRow(DB_FETCHMODE_ORDERED)) $output1 .= join(";", $row) . "n";
echo "Pear result - " . $result_pear->numRows() . " rows: " . number_format((microtime(true) - $time) * 1000, 2, '.', '') . "n";

# ----------

$output2 = "";
$time = microtime(true);
$result_values = $DB->getAll("SELECT * FROM medewerker");
foreach ($result_values as $row) $output2 .= join(";", $row) . "n";
echo "Pear values - " . sizeof($result_values) . " rows: " . number_format((microtime(true) - $time) * 1000, 2, '.', '') . "n";

# ----------

$output3 = "";
$time = microtime(true);
$result_mysql = mysql_query("SELECT * FROM medewerker");
while ($row = mysql_fetch_row($result_mysql)) $output3 .= join(";", $row) . "n";
echo "Mysql result - " . mysql_num_rows($result_mysql) . " rows: " . number_format((microtime(true) - $time) * 1000, 2, '.', '') . "n";


Result:

Pear result - 2427 rows: 3522.35
Pear values - 2427 rows: 3881.87
Mysql result - 2427 rows: 194.67

Do I need to say more.

I'm planning on comparing all common DB interfaces. So keep your eye's out for an article on www.phpit.net.


Good luck,

Arnold Daniels
www.helderhosting.nl

Similar Posts

NeoSmart.net Forum: New 0-day Vulnerability Found in phpBB

PHPEverywhere: Moving Legacy PHP4 apps to PHP 5.1

Community News: Latest PEAR Releases for 08.20.2007

Chris Shiflett\'s Blog: Brain Bulb Webcasts

Community News: New York PHP Conference Session List Posted


Community Events









Don't see your event here?
Let us know!


cakephp application security conference release database PHP5 framework ajax code zendframework releases book mysql package PEAR job example developer zend

All content copyright, 2008 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework