-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
48 lines (33 loc) · 994 Bytes
/
Copy pathDatabase.php
File metadata and controls
48 lines (33 loc) · 994 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
43
44
45
46
47
48
<?php
//Connect to our MySQL database
//PDO php data objects
//initialize PDO
//class Person {
// public $name;
// public $age;
// public function breathe() {
// echo "breathing";
// }
//}
//
//$person = new Person();
//$person ->name ='Adriana';
//$person ->age = 25;
//
//dieAndDump($person);
//Connect to the database and execute a query
class Database {
public $connection;
public function __construct($config, $username='root', $password='') {
// $dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['dbname']};charset={$config['charset']}";
$dsn = 'mysql:' . http_build_query($config, '' ,';');
$this->connection = new PDO($dsn, $username, $password, [
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
}
public function query($query, $id) {
$statement = $this->connection->prepare($query);
$statement->execute($id);
return $statement;
}
}