forked from rgdalessandro/ipohype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.php
71 lines (54 loc) · 1.64 KB
/
connection.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
include_once ( 'config.php' );
class connection
{
public $rows;
private $server = "127.0.0.1";
private $db = 'ipohype';
private $user = MYSQL_USER;
private $pass = MYSQL_PASS;
private $result;
private $link;
private $exectime; //execution time
private $query;
function connection() // function to open a connection to SQL
{
$this->link = new mysqli($this->server, $this->user, $this->pass, $this->db);
if($this->link->connect_errno > 0){
die('Unable to connect to database');
}
else
{
$this->execute("SET NAMES 'utf8'");
}
}
public function numFields() { return $this->link->field_count; }
public function numRows() { return $this->link->num_rows; }
public function displayErr()
{
return $this->link->error;
}
function execute($query) // function to execute an SQL command
{
$this->query = $query;
$this->result = $this->link->query($query);
return $this->result;
}
function fetch() { return $this->rows = $this->result->fetch_assoc(); } // function to return all result rows
public static function fetchOne( $sql ) // functino to return one result row at a time
{
$con = new connection();
$con->execute( $sql );
$con->fetch();
return $con->rows;
}
function getId() // function to return the ID of a result row
{
return $this->link->insert_id;
}
function closeConn() // function to terminate connection to SQL
{
$this->link->close();
}
}
?>