Database Articles

  Home arrow Database Articles arrow Page 4 - Intro to Databases
DATABASE ARTICLES

Intro to Databases
By: lig
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2005-10-18

    Table of Contents:
  • Intro to Databases
  • Database Basics
  • SQL - Structured Query Language
  • Working with Databases
  • Connecting to the database and selecting the database
  • Sending a Query to the Database and Getting the Results
  • Freeing the Results and Closing Down
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Intro to Databases - Working with Databases


    (Page 4 of 8 )

    There are many ways a user can work with a database. The user may use the native functions available through php for the particular database, the PEAR DB package, the ADOdb package, or the user can create a custom database package. Each of these options have good and bad points but we will be discussing and comparing the native functions for a database and the PEAR DB ackage.

    In my examples I will pretend to be using a MySQL database. You can find the native functions for it here in the manual. If you are using a different database system simply go to the user manual and look for your system - there you will find it's listing of available functions. If you still can't find your database system - look at the list of systems supported by the ODBC drivers. I will not be using all of the available functions for MySQL.

    You can find the documentation for the PEAR DB here to look up what I am discussing or for your future reference.

    In this section of the article we will compare/demonstrate native database functions vs. PEAR DB. First we will quickly go over some of the advantages/disadvantages of the 2, then how to connect to the database with each, how to send a query and retreive the results, and lastly how to free the results and close the connection.

    Please notice that I will be including code to handle possible errors that may occur. You should NEVER assume that what should happen always will. All the error code will be commented so you follow what it is doing. Murphy (aka Murphy's Law) tends to pop up when ever and where ever he chooses, so make sure you are ready for him.

    Advantages

    The biggest advantage of native functions is speed. Nothing else compares. The next major advantage is simply that the functions available for a database - maximize the database's effectiveness. Native functions for a database system takes advantage of all the systems capabilities.

    The biggest advantage of PEAR DB is its portability. This package can work with MySQL, PostgreSQL, MSSQL, and a host of others. The only thing that will have to be changed is 1 to 2 lines to switch between database systems. The next major advantage is that it is Object Oriented. With the the new Object Oriented PHP 5 this is a definate advantage.

    Disadvantages

    Native functions are database specific. If you change from a MySQL database to a PostgreSQL database - all your function names will have to be changed. And some function calls that were available in one database system may not be available in another. Also if you are programming with objects - depending on how you program it - you may have to create a wrapper class for the database.

    PEAR DB is slow. Granted there are ways to speed it up but it still will not be as fast as the native functions. Also PEAR DB has a limited number of method calls - so you may have to make 3 rights to go left. Lastly - PEAR DB may not be automatically installed in your server. So you may have to install a local version if you are on a shared server (there are instructions for what to do in the PEAR manual).

    More Database Articles Articles
    More By lig

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap