ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.

Advertisements

Taking a first look at the AutoCRUD for PHP library

(Page 1 out of 5)

Abstract

In this article we'll take a look at the AutoCRUD for PHP library, which is a database abstraction library specifically for MySQL. I'll take you through all major features of this library, and demonstrate everything with examples.

Introduction

Welcome to this article on the AutoCRUD for PHP library. This library is a new database library specifically for MySQL, written by yours truly. I've used many different database libraries in the past, and most of the time I've used a really simple MySQL class, but after while I noticed that some things kept repeating themselves. That's why I decided to write a library that handles 80% of the tasks that need to be done with MySQL, but still allows enough flexibility to make the other 20% possible.

The reason that this library is only compatible with MySQL is that I very rarely need to use another database, and I really wanted to focus on one database. It's possible that the library might get support for other databases in the future, but for now it's strictly MySQL only.

Let's see what the library has to offer

Quick Overview

Although I don't know exactly what other libraries offer, I do believe that this library has a few unique features. For one, it handles relationships between tables automatically, including many-to-many relationships. All you have to do is setup the relationship, which takes only one line of code, and then you're able to select related records from several tables without any hassle.

Another somewhat unique feature is the automatic CRUD functionality, and the enforcing of table structure. When a field in a table has been set to 'NOT NULL', the library will automatically mark that field as 'required', and reject any empty values when using the CRUD functionality. Similarly, the library will also make sure that numeric fields only get numeric data, and the library will reject any non-numeric data.

The full feature list includes:

  • Automatic CRUD functionality: insert, update, read (get/select) and delete
  • Inbuilt support for UNIQUE keys
  • Automatically enforce table structure
  • Handles several different relationships: one-to-one, many-to-one, child-parent and many-to-many
  • Makes it possible to get related records with one line of code
  • Generate table objects on-the-fly
  • Include a seperate CRUD file for higher performance
  • Several different quote functions() to protect against SQL injection
  • Automatically prevents SQL injection when using CRUD functionality
  • Fully tested with over 150 unit tests and live unit tests
  • Experimental ActiveRecord implementation (but not fully functional yet)

Let's get on with the actual library itself. First, head on over to TPG PHP Scripts and download a copy of the latest version (currently 0.1). It's licensed under the MIT license, which means you can use it any way you'd like, making it possible to be used in commercial scripts.

Unzip or untar the library somewhere, and make sure to keep all the files in one directory (although you don't need the 'tests' directory, you can delete it or move it somewhere else). Read on for some live examples.

Next: Setting it all up »



One Response to “Taking a first look at the AutoCRUD for PHP library”

  1. Mac OS X Things » Blog Archive » PHPit - Totally PHP » Taking a first look at the AutoCRUD for PHP library Says:

    […] PHPit - Totally PHP » Taking a first look at the AutoCRUD for PHP library In this article we’ll take a look at the AutoCRUD for PHP library, which is a database abstraction library specifically for MySQL. I’ll take you through all major features of this library, and demonstrate everything with examples. […]

Leave a Reply

About the author
Dennis Pallett is the main contributor to PHPit. He owns several websites, including ASPit and Chill2Music. He is currently still studying.
Article Index
  1. Introduction & Overview
  2. Setting it all up
  3. Basic CRUD functionality
  4. Selecting data
  5. Handling relationships & Conclusion
Bookmark Article
Download Article
PDF
Download this article as a PDF file