forked from catch-design/php-js-dev-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
66 lines (61 loc) · 1.58 KB
/
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
58
59
60
61
62
63
64
65
66
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/catchnz_test/install/config.php');
// load constants, populate in html, then run ...
/**
* db class extending from config class
*/
class db extends config{
public $isConnected = false;
public function __construct() {
parent::__construct();
$this->connect();
}
// mysql connecting method
/**
* connect to mysql db with the given parameters
*/
public function connect(){
if(!$this->isConnected)
{
$this->conn = @mysql_connect($this->db_host,$this->db_username,$this->db_password);
if($this->conn)
{
$selectdb = @mysql_select_db($this->db_name,$this->conn);
if($selectdb)
{
$this->isConnected = true;
return true;
} else
{
return false;
}
} else
{
return false;
}
} else
{
return true;
}
}
// table existance checking ...
/**
* Lchecks if table exists in database
* @param {?string} tableName - name of table to check
*/
public function isTableExists($tableName){
$tablesInDb = @mysql_query('SHOW TABLES FROM '.$this->db_name.' LIKE "'.$tableName.'"');
if($tablesInDb)
{
if(mysql_num_rows($tablesInDb) == 1)
{
return true;
}
else
{
return false;
}
}
}
}
?>