Skip to content
Snippets Groups Projects
Select Git revision
  • 836bb479e13ee6eb735ac95691b3a00cb87eeae1
  • master default
  • v1.1.0
  • v1.0.0
4 results

mysql.php

Blame
  • mysql.php 12.02 KiB
    <?php
    
    class DB
    {
    	private static $db;
    
    	function __construct()
    	{
    		try
    		{
    			self::$db = new PDO(
    				"mysql:host=localhost;dbname=roadmap",
    				"root",
    				"",
    				array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
    
    			self::createTables();
    		}
    		catch(PDOException $e)
    		{
    			die($e);
    		}
    	}
    
    	function createTables()
    	{
    		$statement = self::$db->prepare("CREATE TABLE IF NOT EXISTS `roadmaps` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `Projectname` text COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (`ID`))ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1;");
    		$statement->execute();
    
    		$statement = self::$db->prepare("CREATE TABLE IF NOT EXISTS `milestones` (".
    			"`ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,".
    			"`RoadmapID` int(10) UNSIGNED NOT NULL,".
    			"`VersionCode` int(10) UNSIGNED NOT NULL,".
    			"`VersionName` text COLLATE utf8_general_ci NOT NULL,".
    			"`Title` text COLLATE utf8_general_ci NOT NULL,".
    			"`DueDate` date NOT NULL,".
    			"`CompletionDate` date NOT NULL,".
    			"`Status` int(11) NOT NULL,".
    			"PRIMARY KEY (`ID`)".
    			") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1;");
    		$statement->execute();
    
    		$statement = self::$db->prepare("CREATE TABLE IF NOT EXISTS `tasks` (".
    			"`ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,".
    			"`MilestoneID` int(10) UNSIGNED NOT NULL,".
    			"`Title` text CHARACTER SET utf8 NOT NULL,".
    			"`Description` text CHARACTER SET utf8 NOT NULL,".
    			"`Status` int(11) NOT NULL,".
    			"PRIMARY KEY (`ID`)".
    			") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1;");
    		$statement->execute();
    
    		$statement = self::$db->prepare("CREATE TABLE IF NOT EXISTS `subtasks` (".
    			"`ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,".
    			"`TaskID` int(10) UNSIGNED NOT NULL,".
    			"`Title` text CHARACTER SET utf8 NOT NULL,".
    			"`Description` text CHARACTER SET utf8 NOT NULL,".
    			"`Status` int(11) NOT NULL,".
    			"PRIMARY KEY (`ID`)".
    			") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1;");
    		$statement->execute();
    	}
    
    	//========================================
    	//---------------- insert ----------------
    	//========================================
    
    	function insertRoadmap($projectName)
    	{
    		$statement = self::$db->prepare("INSERT INTO roadmaps VALUES('', :projectName);");