-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDbConnection.php
48 lines (36 loc) · 1.2 KB
/
DbConnection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
class DbConnection
{
public function connect()
{
$servername="localhost";
$username="root";
$password="";
// $conn=null;
try{
// echo "ddddd";
$conn = new PDO('mysql:host=' . $servername . ';dbname=quizizy', $username, $password);
// set the PDO error mode to exception
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//setAttribute() method sets a new value to an attribute.
return $conn;
}
catch(PDOException $e) {
echo $e->getMessage();
die('db error');
}
}
}
$connection = new DbConnection();
$connect = $connection->connect();
class showData extends DbConnection
{
public function AllData(){
$req = $this->connect()->prepare("SELECT choices.choix1, choices.choix2, choices.choix3, choices.choix4, question.question, question.numb, question.answer FROM question INNER JOIN choices on question.id = choices.id");
$req->execute();
return $req->fetchAll();
}
}
$data = new showData();
$all_data = $data->AllData();
echo json_encode($all_data);