https://github.com/alpha-orm/php-alpha-orm
php database orm
https://github.com/alpha-orm/php-alpha-orm
Last synced: 10 months ago
JSON representation
php database orm
- Host: GitHub
- URL: https://github.com/alpha-orm/php-alpha-orm
- Owner: alpha-orm
- License: mit
- Created: 2019-11-11T12:06:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-21T14:59:21.000Z (over 6 years ago)
- Last Synced: 2025-08-17T17:02:12.969Z (11 months ago)
- Language: PHP
- Homepage: https://packagist.org/packages/alpha-orm/alpha-orm
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alpha-orm
An extraordinary python database orm
## Features
* Automatically creates tables and columns
* No configuration required, simply create database
* Currently supported databases include mysql
## Examples
#
### Setup (MySQL)
```php
use ALphaORM\ALphaORM as DB
DB::setup('mysql',[
'host' => 'localhost',
'user' => 'root',
'password' => '',
'database' => 'alphaorm'
]);
```
#
#
### CREATE
```php
#--------------------------------------
# CREATE 1
#--------------------------------------
$product = DB::create('product');
$product->name = 'Running shoes';
$product->price = 5000;
DB::store($product);
#--------------------------------------
# CREATE 2
#--------------------------------------
$author = DB::create('author');
$author->name = 'Chimamanda Adichie';
$book = DB::create('book');
$book->title = 'Purple Hibiscus';
$book->author = $author;
DB::store($book);
```
#
### READ
```php
#--------------------------------------
# READ 1 [get all records]
#--------------------------------------
$books = DB::getAll('book');
foreach ($books as $book) {
print("{$book->title} by {$book->author->name}");
}
#--------------------------------------
# READ 2 [filter one]
#--------------------------------------
$book = DB::find('book','id = :bid', [ 'bid' => 1 ]);
print("{$book->title} by {$book->author->name}");
#--------------------------------------
# READ 3 [filter all]
#--------------------------------------
$author = DB::find('author','name = :authorName',[ 'authorName' => 'William Shakespare' ]);
$booksByShakespare = DB::findAll('book', 'author_id = :authorId', [ 'authorId' => $author->getID() ]);
print('Books by William Shakespare are :');
foreach ($booksByShakespare as $book) {
print($book->title);
}
```
#
### UPDATE
```php
#--------------------------------------
# UPDATE
#--------------------------------------
$product = DB::find('product', 'id = :pid', [ 'pid' => 1 ]);
$product->price = 500;
$book = DB::find('book','id = :bid', [ 'bid' => 1 ]);
$book->author->name = 'New author';
$book->isbn = '3847302-SD';
$book->title = 'New Title';
DB::store($book);
print($book);
```
#
### DELETE
```php
#--------------------------------------
# DELETE 1 [delete single record]
#--------------------------------------
$book = DB::find('book','id = :bid', [ 'bid' => 1 ]);
DB::drop($book);
#--------------------------------------
# DELETE 2 [delete all records]
#--------------------------------------
DB::dropAll('book');
```