Quiz.php
<?php
// by Sketchlife
//follow imsatish709 insta account
//database constants
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'dbpassword');
define('DB_NAME', 'dbname');
//connecting to database and getting the connection object
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//Checking if any error occured while connecting
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
//creating a query
$stmt = $conn->prepare("SELECT ques, a, b, c, d, ans FROM quiz;");
//executing the query
$stmt->execute();
//binding results to the query
$stmt->bind_result($ques, $a, $b, $c, $d, $ans);
$quiz = array();
//traversing through all the result
while($stmt->fetch()){
$temp = array();
$temp['ques'] = $ques;
$temp['a'] = $a;
$temp['b'] = $b;
$temp['c'] = $c;
$temp['d'] = $d;
$temp['ans'] = $ans;
array_push($quiz, $temp);
}
//displaying the result in json format
echo json_encode($quiz);
Json output from above php
Copy and Paste Below code on Your PhpAdmin Section of database ..
Go to SQL section and put below code
-- phpMyAdmin SQL Dump
-- version 4.9.7
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Feb 05, 2023 at 06:06 PM
-- Server version: 10.3.36-MariaDB-cll-lve
-- PHP Version: 7.4.26
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `sketchli_quiz`
--
-- --------------------------------------------------------
--
-- Table structure for table `quiz`
--
CREATE TABLE `quiz` (
`ques` text NOT NULL,
`a` text NOT NULL,
`b` text NOT NULL,
`c` text NOT NULL,
`d` text NOT NULL,
`ans` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Project available on Telegram group sketchlife1
0 Comments