Jums jāizstrādā kāda lielāk projekta prototips. Izstrādājot prototipu, paturiet prātā, ka projektam attīstoties, šo prototipu varētu vajadzēt pilnveidot.
<?php
class DatabaseService
{
private $db;
private $dbConnection;
public function __construct()
{
$this->db = new Database();
//$this->dbConnection = $this->db->getConn();
}
public function isConnected()
{
return $this->db->getServerConnection();
}
public function isDatabaseExists($dbName)
{
try
{
return $this->db->getConn();
}
catch (Exception $e)
{
return false;
}
}
public function createDatabase($dbName)
{
$conn = $this->db->getServerConnection();
$sql = "CREATE Database {$dbName}";
$this->db->query($conn, $sql);
try
{
$sql = "
CREATE TABLE `applications` (
`id` INT NOT NULL AUTO_INCREMENT,
`email` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
`amount` DECIMAL(20,6) NOT NULL DEFAULT '0',
`date_created` DATETIME NOT NULL DEFAULT (curdate()),
PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
";
$this->db->executeSql($sql);
$sql = "
CREATE TABLE `deals` (
`id` INT NOT NULL AUTO_INCREMENT,
`app_id` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
`partner` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
`status` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
`date_created` DATETIME NOT NULL DEFAULT (curdate()),
`date_modified` DATETIME NOT NULL DEFAULT (curdate()),
PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
";
$this->db->executeSql($sql);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
public function execute($sql)
{
$this->db->executeSql($sql);
}
}