PHP code example of transactd / orm
1. Go to this page and download the library: Download transactd/orm library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
transactd / orm example snippets
:
izStation\Transactd\Transactd;
use BizStation\Transactd\Database;
use Transactd\Model;
class Group extends Model
{
public function customers()
{
this->hasMany('Customer', 'group')
}
}
class Customer extends Model
{
public function group()
{
return $this->belongsTo('Group', 'group', 'id');
}
}
// Connect to databases (Master and Slave. These are possible to same host.)
class_alias('Transactd\DatabaseManager', 'DB');
$masterUri = 'tdap://root@masterhost/test?pwd=xxxx';
$slaveUri = 'tdap://root@slavehost/test?pwd=xxxx';
DB::connect($masterUri, $slaveUri);
// Get all customers
$customers = Customer::all();
echo 'The first customer's id = '. $customers[0]->id;
// Get all customers with group relationship in a snapshot.
DB::beginSnapshot();
$customers = Customer::with('group')->all();
DB::endSnapshot();
// Find a customer id = 1
$customer = Customer::find(1);
echo 'The customer name is '. $customer->name;
// Find customers that group number is 3.
// Transactd query are