1. Go to this page and download the library: Download seguncodes/smyorm 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/ */
seguncodes / smyorm example snippets
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testSave() {
// Create a sample object with data
$data = [
'name' => 'Joe',
'email' => '[email protected]',
'role' => 'User'
];
foreach ($data as $attribute => $value) {
$this->orm->{$attribute} = $value;
}
// Call the save() method
$result = $this->orm->save();
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testFindOne() {
// Call the findOne() method
$result = $this->orm->findOne([
"id" => 16,
"name" => "John"
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testfindOneOrWhere() {
// Call the findOneOrWhere() method
$result = $this->orm->findOneOrWhere([
"id" => 16
], [
"role" => "Admin"
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testFindAll() {
// Call the findAll() method
$result = $this->orm->findAll();
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testfindAllWhere() {
// Call the findAllWhere() method
$result = $this->orm->findAllWhere([
"id" => 1
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testfindAllOrWhere() {
// Call the findAllOrWhere() method
$result = $this->orm->findAllOrWhere([
"id" => 13
], [
"name" => "joe"
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testCount() {
// Call the count() method
$result = $this->orm->count();
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testcountWhere() {
// Call the countWhere() method
$result = $this->orm->countWhere([
"id" => 1
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testcountOrWhere() {
// Call the countOrWhere() method
$result = $this->orm->countOrWhere([
"id" => 13
], [
"id" => 15
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testdelete() {
// Call the delete() method
$result = $this->orm->delete([
"id" => 1
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testdeleteOrWhere() {
// Call the countOrWhere() method
$result = $this->orm->deleteOrWhere([
"id" => 13
], [
"id" => 15
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testUpdate() {
// Call the update() method
$result = $this->orm->update([
"name" => "john Doe"
], [
"id" => 13
]);
return $result;
}
}
use SmyORM\SmyORM\Orm;
class User{
private $orm;
public function __construct() {
$this->setUp();
}
public function setUp(): void {
$db = new \PDO('mysql:host=localhost;dbname=yourDatabaseName', 'username', 'password');
// Create a concrete class that extends the ORM class
$this->orm = new class($db) extends Orm {
public function tableName(): string {
return 'users'; // the name of the table that this model references
}
public function attributes(): array {
return ['name', 'email', 'role']; // attributes of the table
}
};
}
public function testupdateOrWhere() {
// Call the updateOrWhere() method
$result = $this->orm->updateOrWhere([
"name" => "Joe doe"
], [
"id" => 17,
"role" => "User"
], [
"id" => 13,
"role" => "Admin"
]);
return $result;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.