2017 © Pedro Peláez
 

library mappeador

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL.

image

mappeador/mappeador

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL.

  • Sunday, October 4, 2015
  • by darkdevilish
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Mappeador by Anthony Gonzalez

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL., (*1)

Configuration

Go to config.php file:, (*2)

defined('DB_SERVER') ? null : define("DB_SERVER", "your_host");
defined('DB_USER')   ? null : define("DB_USER", "your_username");
defined('DB_PASS')   ? null : define("DB_PASS", "your_password");
defined('DB_NAME')   ? null : define("DB_NAME", "db_name");

Usage

First you need to configure the initialize file depending on your file structure and require the file. Once the database and the table is created you have to create class that inherits from Mapper, and create public variables for each table field., (*3)

Example create and table called users with 2 fields id and name, then create the following class:, (*4)

use mappeador\Mapper;

class User extends Mapper {

  protected static $table_name="users";

  public $id;
    public $name;

}

Save function it will return true if saved:, (*5)

$john = new User();
$john->name = "John";
$john->save(); /* or */ $john->create();

Save function at instantiation with array params:, (*6)

$john = new User(array( 'name' => 'John' ));
$john->save(); /* or */ $john->create();

Find all function returns an object array:, (*7)

$users = User::find_all();
foreach($users as $user){
    echo $user->id . " | " . $user->name;
}

To find order by you just have to pass a parameter to find_all(). Example:, (*8)

$users = User::find_all("id DESC");

Find by id (the parameter has to be an integer):, (*9)

$user = User::find_by_id(1);
echo $user->name;

Find where (will return one object if LIMIT 1):, (*10)

$find_johns = User::find_where( "name = ?", array("John") );
$find_john = User::find_where( "name = ? LIMIT 1", array('John') );

Count all:, (*11)

User::count_all();

Update(first you need to find a record, it will return true if updated):, (*12)

$user = User::find_by_id(1);
$user->name = "John";
$user->update(); /* or */ $john->save();

Delete(you need to find record first also, and returns true if deleted):, (*13)

$user = User::find_by_id(1);
$user->name = "John";
$user->delete();

[Note: after deleted it will still be in the object, it will only be deleted from database.], (*14)

Find by sql can be use directly with DatabaseObject class, Mapper or class that inherits from Mapper. If the sql doesn't need sanitazation just pass one parameter with sql otherwise pass 2 parameter the sql and an array with the bind params., (*15)

Example that doesn't need sanitazation(returns object array):, (*16)

use mappeador\DatabaseObject;

$sql = "SELECT * FROM users";
$result_set = DatabaseObject::find_by_sql($sql);

Example that needs sanitazation:, (*17)

use mappeador\DatabaseObject;

$param = array(1);
$sql = "SELECT * FROM users WHERE id=? LIMIT 1";
$result_set = DatabaseObject::find_by_sql($sql, $param);

Mysql query:, (*18)

use mappeador\MySQLDatabase;

$db = MySQLDatabase::getInstance();

$db->query($sql);

[Dangerous: don't use if you need sanitazation.], (*19)

Close connection:, (*20)

use mappeador\MySQLDatabase;

$db = MySQLDatabase::getInstance();
if( isset($db) ) { $db->close_connection(); }

The Versions

04/10 2015

dev-master

9999999-dev https://github.com/darkdevilish/mappeador

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anthony Gonzalez

orm mappeador

30/09 2015

v1.5

1.5.0.0 https://github.com/darkdevilish/mappeador

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anthony Gonzalez

orm mappeador

26/09 2015

v1.4

1.4.0.0 https://github.com/darkdevilish/mappeador

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anthony Gonzalez

orm mappeador

26/09 2015

v1.3

1.3.0.0 https://github.com/darkdevilish/mappeador

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anthony Gonzalez

orm mappeador

25/09 2015

v1.2

1.2.0.0 https://github.com/darkdevilish/mappeador

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anthony Gonzalez

orm mappeador

22/09 2015

v1.1

1.1.0.0 https://github.com/darkdevilish/mappeador

Mappeador is a simple, flexible and easy way to perform php crud with MYSQL.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anthony Gonzalez

orm mappeador