-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
49 lines (34 loc) · 808 Bytes
/
Copy pathdb.php
File metadata and controls
49 lines (34 loc) · 808 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
49
<?php
$hostname = "sql1.njit.edu";
$username = "yz746";
$password = "";
$conn = NULL;
try
{
$conn = new PDO("mysql:host=$hostname;dbname=yz746",
$username, $password);
}
catch(PDOException $e)
{
// echo "Connection failed: " . $e->getMessage();
http_error("500 Internal Server Error\n\n"."There was a SQL error:\n\n" . $e->getMessage());
}
// Runs SQL query and returns results (if valid)
function runQuery($query) {
global $conn;
try {
$q = $conn->prepare($query);
$q->execute();
$results = $q->fetchAll();
$q->closeCursor();
return $results;
} catch (PDOException $e) {
http_error("500 Internal Server Error\n\n"."There was a SQL error:\n\n" . $e->getMessage());
}
}
function http_error($message)
{
header("Content-type: text/plain");
die($message);
}
?>