International Developer Logo Last Updated 25.07.08 at 11.48
On Sale
This months front cover, click to see the table of contents.
Subscribe
 
TUTORIALS

Developing Three-Tier Web Applications with PHP


Daniel Winter   01.10.05

As shown here, it is also good practice to test the DB object for errors after each database action is performed. An alternative method of making a connection is to pass the connect() method an array. In conjunction with an options array, it is also possible to connect via SSL as shown here.

require_once 'DB.php';
$dsn = array(
    'phptype'  => 'mysqli',
    'username' => 'trainingUser',
    'password' => 'qpwo1029',
    'hostspec' => 'localhost',
    'database' => 'onlineTraining',
    'key'      => 'client-key.pem',
    'cert'     => 'client-cert.pem',
    'ca'       => 'cacert.pem',
    'capath'   => '/path/to/ca/dir',
    'cipher'   => 'AES',
);
$options = array(
    'ssl' => true,
);
$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
    die($db->getMessage());
}

The options array supports 6 different configuration settings. The ssl option is a Boolean value that instructs PEAR DB to use a secure sockets layer connection rather than a standard unencrypted TCP/IP connection. Additionally, the autofree Boolean value can be set to instruct the PEAR DB connection to automatically free results when there are no more rows. This is convenient as it removes the need to add cleanup code to each page, but it can be problematic if you want to reuse queries.

Similarly, persistent can be used to create persistent database connections. Again, this can streamline the programming process but can introduce performance issues. The debug parameter can also be optionally used to change the debug level of the library.




   Previous Page  1 2 3 4 5 6 7 8 9 10 ... Next Page   

HAVE YOUR SAY
This article is rated  Rate this article