phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PDO: Improve Performance with Persistent Connection

Tag: PHP Data Objects, PDO, dll, extension, PHP extension, attribute, persistent connection   Category: PHP Database
post: 20 Apr 2008 read: 1,238


PHP Data Objects (PDO) Step By Step Tutorial - Part 15: Persistent connections are known as way to improve performance. When a persistent connection is requested, PHP checks if there's already an identical persistent connection from earlier remained open. If it exists, it uses it. What meaning of remained open? Persistent connection are links that do not close when the execution of your script ends. An 'identical' connection is a connection that was opened to the same host, with the same username and the same password.

How do use it at PDO? PDO have PDO::ATTR_PERSISTENT. We set in the PDO constructor:


<?php
// configuration
$dbtype		= "sqlite";
$dbhost 	= "localhost";
$dbname		= "test";
$dbuser		= "root";
$dbpass		= "admin";

// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass, array(PDO::ATTR_PERSISTENT => true));

// query
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM books";
$q = $conn->query($sql) or die("ERROR: " . implode(":", $conn->errorInfo()));

$r = $q->fetch(PDO::FETCH_ASSOC);

print_r($r);

?>

Please, look at line 10.



Series this article:
PDO: Introduction PHP Data Object
PDO: Activation PHP Data Objects Extension
PDO: Connecting Use PHP Data Object
PDO: Portable Connection to Database
PDO: Posibble Fetch Mode
PDO: Error Handling
PDO: Prepared Statement
PDO: Positional and Named Placeholders
PDO: Insert and Update Statement Use Prepared Statement
PDO: Prepared Statement and Bound Values
PDO: Working With BLOBs
PDO: Alternative Retrieve BLOB Data
PDO: Setting Connection Attributes
PDO: Error Mode Attributes
PDO: Improve Performance with Persistent Connection
PDO: Getting Connection Attributes

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting