microphp/Core/DatabaseMysqlEngine.php

37 lines
1013 B
PHP
Raw Normal View History

2023-04-03 09:14:50 +03:00
<?php
include_once "Helpers.php";
include_once "DatabaseORM.php";
include_once "DatabaseConnection.php";
class MySQLEngine extends DatabaseConnection
{
public function query(ORM $orm)
{
}
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");
});