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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
class mySQL
{
private $connection;
private $selectedDb;
private $result;
private $isConnected;
function __contruct()
{
$this->connection = false;
$this->selectedDb = false;
}
final function connect($host, $user, $password, $db_name, $const = false)
{
if ($const)
$this->connection = @mysql_pconnect($host, $user, $password);
else
$this->connection = @mysql_connect($host, $user, $password);
if ($this->connection)
{
$this->isConnected = true;
if ($this->selectDb($db_name))
$this->selectedDb = true;
return true;
} else
$this->printError();
return false;
}
final private function selectDb($name)
{
if ($this->isConnected)
if (@mysql_select_db($name))
return true;
else
$this->printError();
return false;
}
final function query($sql)
{
if ($this->selectedDb)
{
$this->result = mysql_query($sql);
if ($this->result)
return true;
else
return false;
}
}
final function fetchAssoc($sql = '')
{
if ($this->selectedDb)
{
if (!$this->result)
$this->query($sql);
$rows = array();
while ($row = mysql_fetch_assoc($this->result))
$rows[] = $row;
return $rows;
}
}
final function getRow($sql = '')
{
if ($this->selectedDb)
{
if (!$this->result)
$this->query($sql);
return mysql_result($this->result, 0, 0);
}
}
final function selectNumRows($sql = '')
{
if ($this->selectedDb)
{
if (!$this->result)
$this->query($sql);
return mysql_num_rows($this->result);
}
}
final function close()
{
if ($this->selectedDb)
if (mysql_close())
return true;
return false;
}
final function insert()
{
if ($this->selectedDb)
return mysql_insert_id();
return 0;
}
final private function printError($exit = false)
{
echo "<div style=\"font-family:Verdana; font-size:11px; text-align:center; font-weight: bold;\">Nie mozna ustanowic polaczenia z baza danych MySQL<br />".mysql_errno()." : ".mysql_error()."</div>";
if ($exit)
exit();
}
}
$sql = new mySQL;
$sql->connect('localhost', 'root', 'pass', 'base');
$sql->query("ZAPYTANIE");
$sql->close();
?>





