PHP
  Home arrow PHP arrow Page 4 - Databases and PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Databases and PHP
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2007-06-14


    Table of Contents:
  • Databases and PHP
  • Relational Databases and SQL
  • PEAR DB Basics
  • Data Source Names

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Databases and PHP - Data Source Names
    ( Page 4 of 4 )

    A data source name (DSN) is a string that specifies where the database is located, what kind of database it is, the username and password to use when connecting to the database, and more. The components of a DSN in PEAR are assembled into a URL-like string:

      type(dbsyntax)://username:password@protocol+hostspec/ database

    The only mandatory field is type , which specifies the PHP database backend to use. Table 8-1 lists the implemented database types at the time of writing.

    Table 8-1. PHP database types

    Name Database
    Mysql MySQL
    mysqli MySQL (for MySQL >= 4.1)
    Pgsql PostgreSQL
    Ibase InterBase
    Msql Mini SQL
    Mssql Microsoft SQL Server
    oci8 Oracle 7/8/8i
    Odbc ODBC
    Sybase SyBase
    Ifx Informix
    Fbsql FrontBase
    Dbase DBase
    Sqlite SQLite

    The protocol  is the communication protocol to use. The two common values are "tcp" and "unix , " corresponding to Internet and Unix domain sockets. Not every database backend supports every communications protocol.

    These are some sample valid data source names:

      mysql:///library
      mysql://localhost/library
      mysql://librarian@localhost/library
      mysql://librarian@tcp+localhost/library
      mysql:// librarian:passw0rd@localhost/library

    In Example 8-1, we connected to the MySQL database library with the username librarian and password passw0rd .

    A common development technique is to store the DSN in a PHP file and include that file in every page that requires database connectivity. Doing this means that if the information changes, you don’t have to change every page. In a more sophisticated settings file, you might even switch DSNs based on whether the application is running in development or deployment mode.

    Please check back next week for the continuation of this article.



     
     
    >>> More PHP Articles          >>> More By O'Reilly Media
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT