| 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: <br />'.$Command);
|
|---|
| 29 | } else {
|
|---|
| 30 | return $ReturnCommand;
|
|---|
| 31 | }
|
|---|
| 32 | } // END function SQLCommand
|
|---|
| 33 |
|
|---|
| 34 | function ReadOneRowFromDatabase($SQL) // "SELECT * FROM User"
|
|---|
| 35 | { // BEGIN function ReadFromDatabase
|
|---|
| 36 | $query=$SQL;
|
|---|
| 37 | $result = @mysql_query($query,$this->id_connection);
|
|---|
| 38 | $data = @mysql_fetch_array($result);
|
|---|
| 39 | if (mysql_num_rows($result)<>1) {
|
|---|
| 40 | return false;
|
|---|
| 41 | } else {
|
|---|
| 42 | return $data;
|
|---|
| 43 | }
|
|---|
| 44 | } // END function ReadFromDatabase
|
|---|
| 45 |
|
|---|
| 46 | function Disconnect()
|
|---|
| 47 | { // BEGIN function Disconnect
|
|---|
| 48 | mysql_close($this->id_connection);
|
|---|
| 49 | } // END function Disconnect
|
|---|
| 50 | } // END class Database
|
|---|
| 51 |
|
|---|
| 52 | ?>
|
|---|