seperate class for dbconnection
created class for Movie reindexing
This commit is contained in:
		
							
								
								
									
										55
									
								
								php/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								php/index.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
<?php
 | 
			
		||||
require 'Database.php';
 | 
			
		||||
 | 
			
		||||
$conn = Database::getInstance()->getConnection();
 | 
			
		||||
 | 
			
		||||
if (isset($_POST['action'])) {
 | 
			
		||||
    $action = $_POST['action'];
 | 
			
		||||
    switch ($action) {
 | 
			
		||||
        case "getMovies":
 | 
			
		||||
            echo('{"data":[{"url":"./vid.mp4"}]}');
 | 
			
		||||
            break;
 | 
			
		||||
        case "getDbSize":
 | 
			
		||||
            $query = "SELECT table_schema AS \"Database\", 
 | 
			
		||||
                        ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS \"Size\" 
 | 
			
		||||
                        FROM information_schema.TABLES 
 | 
			
		||||
                        WHERE TABLE_SCHEMA='test'
 | 
			
		||||
                        GROUP BY table_schema;";
 | 
			
		||||
            $result = $conn->query($query);
 | 
			
		||||
 | 
			
		||||
            if ($result->num_rows == 1) {
 | 
			
		||||
                $row = $result->fetch_assoc();
 | 
			
		||||
 | 
			
		||||
                echo '{"data":"' . $row["Size"] . '"}';
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
        case "storePic":
 | 
			
		||||
            // Select file type
 | 
			
		||||
            $imageFileType = strtolower(pathinfo("./lukas.png", PATHINFO_EXTENSION));
 | 
			
		||||
            // Convert to base64
 | 
			
		||||
            $image_base64 = base64_encode(file_get_contents("./lukas.png"));
 | 
			
		||||
            $image = 'data:image/' . $imageFileType . ';base64,' . $image_base64;
 | 
			
		||||
            // Insert record
 | 
			
		||||
            $query = "insert into temppic(data) values('" . $image . "')";
 | 
			
		||||
            if ($conn->query($query) === TRUE) {
 | 
			
		||||
                echo('{"data":"successfully created entry"}');
 | 
			
		||||
            } else {
 | 
			
		||||
                echo('{"data":"' . $conn->error . '"}');
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case "readPic":
 | 
			
		||||
            $query = "SELECT * FROM temppic WHERE id='5'";
 | 
			
		||||
 | 
			
		||||
            $result = $conn->query($query);
 | 
			
		||||
            $row = $result->fetch_assoc();
 | 
			
		||||
 | 
			
		||||
            echo('{"data":"' . $row["data"] . '"}');
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
} else {
 | 
			
		||||
    echo('{"data":"error"}');
 | 
			
		||||
}
 | 
			
		||||
$conn->close();
 | 
			
		||||
return;
 | 
			
		||||
		Reference in New Issue
	
	Block a user