mysql_setup.php

<?php
    include("database_credentials.php"); // define variables

    /** SETUP **/
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $db = new mysqli($dbhost, $dbusername, $dbpasswd, $dbname);
    
    $db->query("drop table if exists question;");
    $db->query("create table question (
        id int not null auto_increment,
        question text not null,
        answer text not null,
        points int not null,
        primary key (id));");
    
    $db->query("drop table if exists user;");
    $db->query("create table user (
        id int not null auto_increment,
        email text not null,
        name text not null,
        password text not null,
        primary key (id));");


    $db->query("drop table if exists user_question;");
    $db->query("create table user_question (
        user_id int not null,
        question_id int not null,
        points int not null);");
        
   
   
   
    $data = json_decode(file_get_contents("https://opentdb.com/api.php?amount=50&category=14&difficulty=medium&type=multiple"), true);
    
    print_r($data);
    
    $points = 10;
    $stmt = $db->prepare("insert into question (question, answer, points) values (?,?,?);");
    foreach($data["results"] as $qn) {
        $stmt->bind_param("ssi", $qn["question"], $qn["correct_answer"], $points);
        if (!$stmt->execute()) {
            echo "Could not add question: {$qn["question"]}\n";
        }
        
        
    }