-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBtest.php
More file actions
42 lines (30 loc) · 867 Bytes
/
DBtest.php
File metadata and controls
42 lines (30 loc) · 867 Bytes
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
<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/src/DB.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/src/dotenv.php");
// selecting
try{
$db = new DB;
$conn = $db->get_connection();
$query = "SELECT * FROM authors";
$data = $conn->query($query);
} catch (PDOException $e) {
throw $e;
}
foreach($data as $row){
echo "<h4>". $row['name'] ."</h4>";
echo "<img src=\"". $row['portrait_url'] ."\" />";
}
// inserting
// $name = "Joe Bloggs";
// $url = "someimage.jpg";
// try{
// $query = "INSERT INTO authors (name, portrait_url) VALUES(:name, :portrait_url)";
// $result = $conn->prepare($query);
// $result->bindParam(':name', $name);
// $result->bindParam(':portrait_url', $url);
// if($result->execute()){
// echo "row inserted";
// }
// } catch (PDOException $e) {
// throw $e;
// }