utipd/mysqlmodel

A minimalistic manager for storing and retrieving MySQL rows as PHP models. Does not handle schemas. Does allow treating mysql rows like documents.

0.0.1 2014-08-28 15:25 UTC

This package is not auto-updated.

Last update: 2024-11-19 02:54:34 UTC


README

A MysqlModel component for UTipdMe.

Build Status

A simple ORM to map MySQL table rows to PHP models and back.

Usage Example:

<?php 

// create a class
//   this maps to table user in MySQL (you must create this yourself)
class UserDirectory extends \Utipd\MysqlModel\BaseDocumentMysqlDirectory {

    protected $column_names = ['email'];

}

// pass in your PDO object
$user_directory = new UserDirectory(new \PDO('mysql:dbname=testdb;host=127.0.0.1'));

// find by email
$user = $user_directory->findOne(['email' => 'johny@appleseed.com']);

// access rows and properties
print $user['email']."\n";

// update in MySQL, adding arbitrary columns
$user_directory->update($user, ['firstName' => 'John', 'lastName' => 'Appleseed']);

// get the user again from the database
$user = $user_directory->reload($user);
print $user['firstName']." ".$user['lastName']."\n";