You are currently browsing Crystal’s documentation for the 0.4 version - Switch to version: 0.3

Introduction

What is Crystal

Crystal is a minimalistic database wrapper for PHP. Crystal was designed to replace framework specific database layers like Zend_Db and Codeigniter's active record library and complex ORM's like Doctrine.

Crystal's main goal is to help developers build and scale reusable, database dependent, framework agnostic applications.

Crystal core


Crystal contains three independent core components:

Database wrapper - for CRUD operations
Validation module - provides a comprehensive data validation
Database manipulation module - used for creating databases, tables, etc.

Key concepts

Crystal is all about writing readable and DRY code. It is just concentrated on the task - writing and executing SQL queries. No additional magic like defining models is required - you just include Crystal.php, define your database access details and start working.

One of the main Crystal concepts is minimizing surprise when writing queries. If you already know SQL - learning Crystal will take you minutes. Here is a quick example:

$db->select('client_name, client_email')->from('clients')->where('client_id : 2, client_status : active')

//Or you can write :

$db->get('clients')->where('client_id : 2, client_status : active')

// Produces SELECT * FROM `clients` WHERE `client_id`='2' AND `client_status` = 'active'

Real world usage