Создать простой сайт, где будет страница с формой для авторизации и страница для авторизованного пользователя.
<?php
class DatabaseService
{
public $hostname;
public $username;
public $password;
public $db;
public function __construct()
{
$this->db = new Database();
}
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->createDatabase($sql);
try
{
$sql = "
CREATE TABLE `users` (
`id` INT NOT NULL AUTO_INCREMENT,
`login` VARCHAR(20) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
`password` VARCHAR(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
";
$this->db->executeSql($sql);
$sql = "
CREATE TABLE `content_items` (
`item_id` INT NOT NULL AUTO_INCREMENT,
`parent_id` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
`title` VARCHAR(100) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
`description` VARCHAR(500) 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 (`item_id`) USING BTREE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
";
$this->db->executeSql($sql);
}
catch (Exception $e)
{
echo $e->getMessage();
}
$this->db->executeSql("INSERT INTO users (login, password) VALUES ('user1', 'a')");
$this->db->executeSql("INSERT INTO users (login, password) VALUES ('user2', 'a')");
$this->db->executeSql("INSERT INTO content_items (parent_id, title, description) VALUES (0, 'PHP Manual', 'PHP, which stands for \"PHP: Hypertext Preprocessor\" is a widely-used Open Source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated web pages quickly, but you can do much more with PHP.')");
$this->db->executeSql("INSERT INTO content_items (parent_id, title, description) VALUES (2, 'PHP description', 'PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.')");
$this->db->executeSql("INSERT INTO content_items (parent_id, title, description) VALUES (2, 'What can PHP do?', 'Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more. There are three main areas where PHP scripts are used.')");
$this->db->executeSql("INSERT INTO content_items (parent_id, title, description) VALUES (1, 'Language Reference', '')");
$this->db->executeSql("INSERT INTO content_items (parent_id, title, description) VALUES (5, 'Basic syntax', '')");
$this->db->executeSql("INSERT INTO content_items (parent_id, title, description) VALUES (6, 'PHP tags', 'When PHP parses a file, it looks for opening and closing tags, which are <?php and ?> which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows PHP to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser. PHP includes a short echo tag <?= which is a short-hand to the more verbose <?php echo. ')");
$this->db->executeSql("INSERT INTO content_items (parent_id, title, description) VALUES (6, 'Instruction separation', 'As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of each statement. The closing tag of a block of PHP code automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block. The closing tag for the block will include the immediately trailing newline if one is present.')");
$this->db->executeSql("INSERT INTO content_items (parent_id, title, description) VALUES (1, 'Introduction', '')");
}
public function execute($sql)
{
$this->db->executeSql($sql);
}
public function query($sql)
{
return $this->db->query($sql);
}
}