source: quests/6.6. 23-00/DatabaseConection.php@ 39

Last change on this file since 39 was 39, checked in by george, 18 years ago

Korekce velikosti písmen přípony obrázků.

File size: 1.5 KB
Line 
1<?php
2 class Database
3 { // BEGIN class Database
4 // variables
5 var $id_connection = 0;
6 // var $LastResult;
7
8
9 // constructor
10 function Database($addres,$user,$pass) //default: $Database = new Database('localhost','root','');
11 { // BEGIN constructor
12 $this->id_connection = mysql_connect($addres,$user,$pass);
13 if (!$this->id_connection)
14 die('Spojení s MySQL databází se nezdaøilo.');
15 } // END constructor
16
17 function SelectDatabase($NameDatabase)
18 { // BEGIN function SelectDatabase
19 $return_selection = mysql_select_db($NameDatabase,$this->id_connection);
20 if (!$return_selection)
21 die('Databázi pokus se nám nepodaøilo vybrat.');
22 } // END function SelectDatabase
23
24 function SQLCommand($Command)
25 { // BEGIN function SQLCommand
26 $ReturnCommand = mysql_query($Command,$this->id_connection);
27 if (!$ReturnCommand) {
28 die('Nepodaøilo se aplikovat pøíkaz.');
29 } else {
30 return $ReturnCommand;
31 }
32 } // END function SQLCommand
33
34 function ReadFromDatabase($SQL) // "SELECT * FROM User"
35 { // BEGIN function ReadFromDatabase
36 $return_result = mysql_query($sql,$id_spojeni);
37 if (!$return_result) {
38 die('Nepodaøilo se nám naèíst øádky z databáze.');
39 } else {
40 return $return_result;
41 }
42 } // END function ReadFromDatabase
43
44 function Disconnect()
45 { // BEGIN function Disconnect
46 mysql_close($this->id_connection);
47 } // END function Disconnect
48 } // END class Database
49
50?>
Note: See TracBrowser for help on using the repository browser.