1. Go to this page and download the library: Download tabusoft/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/ */
tabusoft / orm example snippets
namespace Application\Entities;
use Tabusoft\ORM\Entity\EntityAbstract;
use Application\Entities\Descriptors\ForumCategoryDescriptor;
/**
*
* @database test_forum
* @table forum_category
*
**/
class ForumCategory extends EntityAbstract
{
use ForumCategoryDescriptor;
/** implements here your class methods */
}
namespace Application\Entities;
use Tabusoft\ORM\Entity\EntityAbstract;
use Application\Entities\Descriptors\ForumTopicsDescriptor;
/**
*
* @database test_forum
* @table forum_topics
*
**/
class ForumTopics extends EntityAbstract
{
use ForumTopicsDescriptor;
/** implements here your class methods */
}
//init the tabusoft/db
$db_config = new \Tabusoft\DB\DBFactoryConfig("localhost","test","test_username","test_password");
\Tabusoft\DB\DBFactory::getInstance($db_config);
//empty object
$category = new Application\Entities\Category();
//obtain the repository
$repo = Application\Entities\ForumCategory()::getRepository();
//or
$repo = new Application\Repository\ForumCategoryRepository();
$category = $repo->findById(1323);
//init the query object
$query = new EQB();
//init two EQBEntity refered to the relative Entities class.
$fc = new EQBEntity(ForumCategory::class);
$ft = new EQBEntity(ForumTopics::class);
//doing a select:
//this will return two result containing:
//a ForumCategory entity, a ForumTopic entity,
//and the id column of forum category enitity.
$query = $q->select( $ft, $fc, $fc->id->as("id") );
$query->from($ft);
$query->where($fc->id, "IN (?)")->pushValue([1,2]);
$res = $query->query();
//or in the short mode:
$res = $q->select( $ft, $fc, $fc->id->as("id") )
->from($ft);
->where($fc->id, "IN (?)");
->query([1,2]);
//res is a traversable collection of: [ ForumTopic object, ForumCategory Object, id ]
foreach($res as $r){
var_dump($r);
}