composer require sandeshshrestha/tiny-orm
Define few constants.
// Define __FILE_STORAGE_PATH__ constant where the FileStorage::save() method saves the file.
define("__FILE_STORAGE_PATH__", __DIR__ . '/uploaded_files/');
// Define __DATABASE_CONFIG__ constant that will be used by Database.php to connect to database
define("__DATABASE_CONFIG__", [
'type' => 'mysql',
'host' => 'mysql.example.com',
'username' => 'db_username',
'password' => 'db_password',
'database' => 'db_name',
'table_prefix' => 'db_table_prefix',
'port' => 3306
]);
Create database tables
CREATE TABLE `db_table_prefix_user` (
`id` varchar(255) NOT NULL,
`fullName` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
use TinyORM\Model;
class User extends Model {
protected $table = 'user';
protected $primaryKey = 'id';
protected $fillable = ["fullName", "email"];
}
$user = new User();
$user->fullName = "John Doe";
$user->email = "[email protected]";
$user->save();
$user2 = User::create([
'fullName' => "John Doe 2",
"email" => "[email protected]",
]);
$foundUser = User::find($user->getPrimaryValue());
$foundUser->delete();
$users = User::where("fullName", "John Doe")->limit(1)->orderBy('id')->exec();