-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
57 lines (47 loc) · 976 Bytes
/
db.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
48
49
50
51
52
53
54
55
56
57
<?php
/*
* DCE TOOLS
* - DB Lib
*/
//Open and return database connection
function getconn($username, $password, $dbname)
{
// Create connection
$conn = new mysqli(localhost, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
return $conn;
}
//close database connection
function closeconn($conn)
{
$conn->close();
}
//Execute query and return result
function getresult($conn, $sql)
{
$result = $conn->query($sql);
return $result;
}
//Execute NonQuery
function executenonquery($conn, $sql)
{
if ($conn->query($sql) === FALSE)
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
//Insert row and return id of inserted row
function insertandgetid($conn, $sql)
{
if ($conn->query($sql) === FALSE)
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$last_id = $conn->insert_id;
return $last_id;
}
?>