diff --git a/config/database.sql b/config/database.sql new file mode 100644 index 0000000..b40cf87 --- /dev/null +++ b/config/database.sql @@ -0,0 +1,43 @@ +-- +-- Create database +-- + +DROP DATABASE IF EXISTS `PHPStarter`; +CREATE DATABASE IF NOT EXISTS `PHPStarter`; + +USE `PHPStarter`; + +-- +-- Create user for database +-- + +DROP USER IF EXISTS 'PHPStarter_user'@'localhost'; +CREATE USER 'PHPStarter_user'@'localhost' IDENTIFIED BY ''; + +GRANT ALL PRIVILEGES ON `PHPStarter`.* TO 'PHPStarter_user'@'localhost'; +FLUSH PRIVILEGES; + +-- +-- Drop tables +-- + +DROP TABLE IF EXISTS `PHPStarter`; + +-- +-- Table structure for 'PHPStarter' +-- + +CREATE TABLE `PHPStarter` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `message` VARCHAR(255) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- +-- Reset 'PHPStarter' +-- + +DELETE FROM `PHPStarter`; +ALTER TABLE `PHPStarter` AUTO_INCREMENT = 1; + +INSERT INTO `PHPStarter` (`message`) VALUES +("Welcome to PHPStarter"); diff --git a/public/index.php b/public/index.php index e8d2b9f..da59132 100644 --- a/public/index.php +++ b/public/index.php @@ -1,13 +1,34 @@ +load(); + +use PHPStarter\DB; + +$pdo = DB::connect(); + +$query = "SELECT * FROM `PHPStarter` WHERE `id` = 1"; +$stmt = $pdo->prepare($query); +$stmt->execute(); + +$PHPStarter = $stmt->fetch(); + +?> +
-