Micro-ORM/index.php

45 lines
852 B
PHP
Raw Normal View History

2021-02-26 21:00:00 +00:00
<?php
2021-02-26 21:11:56 +00:00
namespace Sieciech\Orm8;
2021-02-26 21:00:00 +00:00
interface ISqlBase {
public function Get(): string;
//public function Insert(): string;
//public function Update(): string;
//public function Delete(): string;
}
2021-02-26 21:08:57 +00:00
abstract class BaseModel {
2021-02-26 21:00:00 +00:00
protected $sql;
public function __construct(ISqlBase $sql) {
$this->sql = $sql;
}
public static function Get(int $id) {
2021-02-26 21:10:22 +00:00
return get_called_class();
2021-02-26 21:00:00 +00:00
$stmt = $pdo->prepare('SELECT id, name FROM users WHERE id=?');
$stmt->execute([$id]);
return $stmt->fetchObject(__CLASS__);
}
}
class JobSql implements ISqlBase {
public function Get(): string {
return "";
}
}
class Job extends BaseModel {
public function __construct() {
parent::__construct( new JobSql() );
}
}
2021-02-26 21:11:56 +00:00
echo "
2021-02-26 21:00:00 +00:00
2021-02-26 21:11:56 +00:00
";
2021-02-26 21:00:00 +00:00
echo Job::Get(10);
2021-02-26 21:11:56 +00:00
echo "
";