mysql host localhost mysql user root mysql pass root mysql base thisne

 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
72
73
74
<?
$mysql['host'] = 'localhost';
$mysql['user'] = 'root';
$mysql['pass'] = 'root';
$mysql['base'] = 'thisnext';
class DB {
private $conn = null;
public function __construct() {
global $mysql;
$this->conn = @mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']);
if($this->conn) {
$base = @mysql_select_db($mysql['base'], $this->conn);
if(!$base) {
die('Не удалось выбрать базу "'.$mysql['base'].'"');
}
mysql_query('SET character_set_client = utf8', $this->conn);
mysql_query('SET character_set_connection = utf8', $this->conn);
mysql_query('SET character_set_results = utf8', $this->conn);
} else {
die('Не удалось подключиться к БД MySQL');
}
}
public function __destruct() {
if($this->conn) {
mysql_close($this->conn);
}
}
public function query($sql) {
$temp = mysql_query($sql, $this->conn);
return $temp;
}
public function estr($str) {
$temp = mysql_real_escape_string($str, $this->conn);
return $temp;
}
public function row($sql) {
$result = mysql_query($sql, $this->conn);
if($result && ($row = mysql_fetch_assoc($result))) {
return $row;
} else {
return false;
}
}
public function rows($sql) {
$result = mysql_query($sql, $this->conn);
if($result) {
$rows = array();
while($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
} else {
return false;
}
}
public function num_rows($sql) {
$result = mysql_query($sql, $this->conn);
if($result) {
$num = mysql_num_rows($result);
return $num;
} else {
return false;
}
}
}
?>