Creating a Custom Database Class

The DMX Server Behaviors make it easy for new users to connect to a database and perform various operations, without them having to know how to create the code themselves. However, they are general purpose as they have to work in a range of different situations. The code created is complex, inefficient, and makes it extremely difficult to perform a range of different database operations on a single page.

In this 11 page article, Gareth shows you how to create a custom Database class, which makes it easy to perform Database Operations from your own code, and which can be used to replace the Dreamweaver MX Server Behaviors.
$2.79
- OR -

Overview

Table of Contents:

  • Why replace the Dreamweaver MX Server Behaviors?
  • A Quick Reminder of SQL
  • Reading Records from a Database Table – SELECT
  • Adding Records to a Database Table – INSERT INTO
  • Updating Records in a Database Table – UPDATE
  • Deleting Records from a Database Table – DELETE
  • The SQL WHERE Clause
  • Building the Database Class
  • Method: openDatabase()
    • Using mysql_connect
    • Using mysql_select_db
  • Method: closeDatabase()
  • Method: addRecord($fields,$values,$tableName)
  • Method: updateRecord($fields,$values,$table,$where)
  • Method: deleteRecord($table,$where)
  • Method: arrayToWhere($values,$fieldName)
  • Method: readFromDatabase($sql)
  • Method: numRecords()
  • Method: function showError($error, $sql = "")
  • Splitting the Database Class using Class Inheritance
  • Using the Database Class for your own Sites
  • Adding a record to the Database
  • Updating a Record in the Database
  • Deleting a Record from the Database
  • Reading Records from a Database
  • Putting it all together
  • Expanding the Class

Gareth Downes-Powell

Gareth Downes-PowellGareth has a range of skills, covering many computer and internet related subjects. He is proficient in many different languages including ASP and PHP, and is responsible for the setup and maintenance of both Windows and Linux servers on a daily basis.


In his daily web development work he uses the complete range of Macromedia software, including Dreamweaver MX, Flash MX, Fireworks MX and Director to build a number of websites and applications. Gareth has a close relationship with Macromedia, and as a member of Team Macromedia Dreamweaver, he has worked closely in the development of Dreamweaver, and was a beta tester for Dreamweaver MX.


On a daily basis he provides support for users in the Macromedia forums, answering questions and providing help on a range of different web related subjects. He has also written a number of free and commercial extensions for Dreamweaver MX, to further extend its capabilities using its native JavaScript API’s or C++.


As a web host, Gareth has worked with a range of different servers and operating systems, with the Linux OS as his personal favourite. Most of his development work is done using a combination of Linux, Apache and MySQL and he has written extensively about setting up this type of system, and also running Apache and MySQL under Windows.

See All Postings From Gareth Downes-Powell >>

Reviews

Be the first to write a review

You must me logged in to write a review.