2017 © Pedro Peláez
 

library php-easy-db

Easy to use MySQL and PostgreSQL database library for PHP.

image

keysmash/php-easy-db

Easy to use MySQL and PostgreSQL database library for PHP.

  • Wednesday, July 1, 2015
  • by sgtkode
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

PHP-EasyDB

Easy to use MySQL and PostgreSQL database library for PHP.

Disclaimer: This is a heavily modified version of the database classes used in the PHP Beyond the the Basics Lynda tutorial. I am not trying to steal the original IP., (*1)

Create a database object using params:

type, host, database name, user, password, (*2)

// 1 for mysql
$db = new Database(1, "localhost", "foobar", "root", "toor");
// 2 for postgres
$db = new Database(2, "localhost", "foobar", "root", "toor");

Create base class and extend DatabaseTable

class Test extends DatabaseTable {
  protected static $table_name = "test";
  protected static $db_fields = array(
    'id',
    'test'
  );
  protected static $db_types = array(
    'int(11) NOT NULL',         // id
    'varchar(11) NOT NULL'     // test
  );

  public $id;
  public $test;

  public static function find_by_test($database, $test){
    $sql = "SELECT * FROM " . static::$table_name . " WHERE test=" . $test;
    $result_array = static::find_by_sql($database, $sql);
    return !empty($result_array) ? $result_array : false;
  }
}

Get row by id

$row = Test::find_by_id($db, 1);

Use custom function to find row(s)

$rows = Test::find_by_test($db, "foobar");

Get row(s) with specific sql

$rows = Test::find_by_sql($db, "SELECT * FROM test LIMIT 3 ORDER BY ASC");

Get array of all rows

$rows = Test::find_all($db);

Loop through rows

foreach($rows as $row){
  // do stuff
}

Get data from row

echo $row->test;

Set row data

$row->test = "foobar";

Save row

if($row->save()){
  echo "yeah, it worked!";
} else {
  echo "dang it";
}

Delete row

if($row->delete()){
  echo "yeah, it worked!";
} else {
  echo "dang it";
}

The Versions

01/07 2015

dev-master

9999999-dev http://keysmashstudios.com

Easy to use MySQL and PostgreSQL database library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

database php postgresql mysql

01/07 2015

v1.0.2

1.0.2.0 http://keysmashstudios.com

Easy to use MySQL and PostgreSQL database library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

database php postgresql mysql

09/06 2015

v1.0.1

1.0.1.0 http://keysmashstudios.com

Easy to use MySQL and PostgreSQL database library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

database php postgresql mysql

09/06 2015

v1.0.0

1.0.0.0 http://keysmashstudios.com

Easy to use MySQL and PostgreSQL database library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

database php postgresql mysql