37 lines
1.0 KiB
PHP
Executable File
37 lines
1.0 KiB
PHP
Executable File
<?php
|
|
include_once "Helpers.php";
|
|
include_once "DatabaseORM.php";
|
|
include_once "DatabaseConnection.php";
|
|
|
|
class MySQLEngine extends DatabaseConnection
|
|
{
|
|
public function query(ORM $orm)
|
|
{
|
|
return $this->exec();
|
|
}
|
|
public function migrate(ORMMigrate $orm)
|
|
{
|
|
$sql = [];
|
|
$sql[] = "CREATE TABLE IF NOT EXISTS ";
|
|
$sql[] = $orm->table;
|
|
$sql[] = " ( ";
|
|
$columns = [];
|
|
foreach ($orm->columns as $name => $value) {
|
|
$type = $value[0];
|
|
$propety = $value[1] ?? "";
|
|
$columns[] = "$name $type $propety";
|
|
}
|
|
$sql[] = implode(", ",$columns);
|
|
$sql[] = ") charset=" . $orm->charset;
|
|
|
|
}
|
|
}
|
|
|
|
ORM::$defaultConnection = new MySQLEngine("mysql","root","");
|
|
|
|
|
|
ORM::migrate(function($table){
|
|
$table->id("int","auto_increment primary key");
|
|
$table->name("text");
|
|
$table->value("text");
|
|
}); |