summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-10-02 21:29:53 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-10-02 21:29:53 +0530
commitfa0fed060e5cb9a2ef365a60a24a576282a86016 (patch)
treec0096a3b915eef200dc52165c763d94d07e79ee6
parent71a5768da1b297c807beee4e3c6a4942126c66e9 (diff)
Lab04: Add database table creation php file + Docker configuration for AMP+phpmyadmin
-rw-r--r--Lab04/Dockerfile7
-rw-r--r--Lab04/create_table.php38
-rw-r--r--Lab04/docker-compose.yml37
3 files changed, 82 insertions, 0 deletions
diff --git a/Lab04/Dockerfile b/Lab04/Dockerfile
new file mode 100644
index 0000000..01effe1
--- /dev/null
+++ b/Lab04/Dockerfile
@@ -0,0 +1,7 @@
+FROM php:7.4-apache
+
+RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
+
+COPY . /var/www/html
+
+WORKDIR /var/www/html
diff --git a/Lab04/create_table.php b/Lab04/create_table.php
new file mode 100644
index 0000000..1cc0069
--- /dev/null
+++ b/Lab04/create_table.php
@@ -0,0 +1,38 @@
+<?php
+$servername = "db";
+$username = "example";
+$password = "example";
+$database = "regformdata";
+$tableName = "regtable";
+
+// Create connection
+$conn = new mysqli($servername, $username, $password);
+
+// Check connection
+if ($conn->connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+
+// Select the database
+$conn->select_db($database);
+
+// Create table
+$sql = "CREATE TABLE `$tableName` (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ fname VARCHAR(50) NOT NULL,
+ lname VARCHAR(50) NOT NULL,
+ gender VARCHAR(10),
+ phone VARCHAR(15),
+ email VARCHAR(100),
+ city VARCHAR(50),
+ department VARCHAR(50)
+)";
+
+if ($conn->query($sql) === TRUE) {
+ echo "Table created successfully";
+} else {
+ echo "Error creating Table: " . $conn->error;
+}
+
+$conn->close();
+?> \ No newline at end of file
diff --git a/Lab04/docker-compose.yml b/Lab04/docker-compose.yml
new file mode 100644
index 0000000..1e40524
--- /dev/null
+++ b/Lab04/docker-compose.yml
@@ -0,0 +1,37 @@
+version: '3.1'
+
+services:
+ db:
+ image: mysql
+ restart: always
+ environment:
+ MYSQL_ROOT_PASSWORD: example
+ MYSQL_DATABASE: regformdata
+ MYSQL_USER: example
+ MYSQL_PASSWORD: example
+ ports:
+ - "3306:3306"
+ volumes:
+ - db_data:/var/lib/mysql
+
+ php:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ restart: always
+ ports:
+ - "80:80"
+
+ phpmyadmin:
+ image: phpmyadmin/phpmyadmin
+ restart: always
+ environment:
+ PMA_HOST: db
+ MYSQL_ROOT_PASSWORD: example
+ ports:
+ - "8080:80"
+ depends_on:
+ - db
+
+volumes:
+ db_data: