Skip to content

cyrilsuzat/activerecord_php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Run the examples

1. Create the database structure:

CREATE TABLE `posts` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `title` VARCHAR(255) NULL,
  `body` TEXT NULL,
  `created_at` DATETIME NULL,
  `updated_at` DATETIME NULL
);
CREATE TABLE `comments` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `post_id` INT NOT NULL ,
  `author` VARCHAR(255) NULL,
  `content` TEXT NULL,
  `created_at` DATETIME NULL,
  `updated_at` DATETIME NULL
);

2. Setup the config.php file

3. Run main.php

Notes

  • Delete DbTable::get_called_class() if using PHP>=5.3.0
  • Respect the following conventions:
    • Name id the column of the primary key
    • Foreign keys like {foreign-table}_id (ex: post_id)
    • Tables must contains created_at and updated_at cols
    • Params staring with underscore (_) don't go into DB ex: new User(array('_create'=>'Create', 'name'=>'Joe'))

Credits

Created by Cyril Suzat

About

An implementation of the ActiveRecord design pattern in PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages