1. Go to this page and download the library: Download met_mw/sorm 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/ */
met_mw / sorm example snippets
/**
* FirstModel
*
* @property int $id
* @property string $name
*/
class FirstModel extends Entity
{
protected $tableName = 'first_model_table_name';
public function getFirstModelChilds()
{
/** @var FirstModelChild[] $aFirstModelChilds */
$aFirstModelChilds = $this->findRelationCache('id', FirstModelChild::cls()); // Search in cache
if (empty($aFirstModelChilds)) { // If no cache, then load data from data source
$oFirstModelChilds = DataSource::i()->factory(FirstModelChild::cls()); // Create empty model
$oFirstModelChilds->getQueryBuilder()
->where('first_model_id', '=', $this->id); // Build search conditions
$aFirstModelChilds = $oFirstModelChilds->loadAll();
// Caching data
foreach ($aFirstModelChilds as $oFirstModelChild) {
$this->addRelationCache('id', $oFirstModelChild);
$oFirstModelChild->addRelationCache('first_model_id', $this);
}
}
return $aFirstModelChilds;
}
}
/**
* FirstModelChild
*
* @property int $id
* @property string $name
* @property int $first_model_id
*/
class FirstModelChild extends Entity
{
protected $tableName = 'fist_model_child_table_name';
public function getFirstModel()
{
/** @var FirstModel[] $aFirstModels */
$aFirstModels = $this->findRelationCache('id', FirstModel::cls()); // Search in cache
if (empty($aFirstModels)) { // If no cache, then load data from data source
$oFirstModels = DataSource::i()->factory(FirstModel::cls()); // Create empty model
$oFirstModels->getQueryBuilder()
->where('id', '=', $this->first_model_id); // Build search conditions
$aFirstModels = $oFirstModels->loadAll();
// Caching data
foreach ($aFirstModels as $oFirstModel) {
$this->addRelationCache('first_model_id $oFirstModel);
$oFirstModel->addRelationCache('id', $this);
}
}
return isset($aFirstModels[0]) ? $aFirstModels[0] : null;
}
}
DataSource::d()->query('select * from `table_name`'); // Execute query
$result = DataSource::d()->fetchAll(); // Fetch all data as array
DataSource::d()->query('select * from `table_name`'); // Execute query
$result = DataSource::d()->fetchAllAssoc(); // Fetch all data as assoc array
DataSource::d()->query('select * from `table_name`'); // Execute query
$result = DataSource::d()->fetchRow(); // Fetch data row as array
DataSource::d()->query('select * from `table_name`'); // Execute query
$result = DataSource::d()->fetchRowAssoc(); // Fetch data row as assoc array
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.