- Timestamp:
- Jan 24, 2009, 7:49:23 PM (16 years ago)
- Location:
- includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
includes/databaseconection.php
r40 r41 1 1 <?php 2 class Database3 { // BEGIN class Database4 // variables5 var $id_connection = 0;6 // var $LastResult;7 8 2 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 3 class Database 4 { 5 var $id_connection = 0; 6 7 function Database($address = 'localhost', $user = 'root', $pass = '') 8 { 9 $this->id_connection = mysql_connect($address, $user, $pass); 10 if(!$this->id_connection) 11 die('Spojení s MySQL databází se nezdařilo.'); 12 } 16 13 17 18 { // BEGIN function SelectDatabase19 $return_selection = mysql_select_db($NameDatabase, $this->id_connection);20 if 21 die('Databázi pokusse nám nepodařilo vybrat.');22 } // END function SelectDatabase14 function SelectDatabase($NameDatabase) 15 { 16 $return_selection = mysql_select_db($NameDatabase, $this->id_connection); 17 if(!$return_selection) 18 die('Databázi '.$NameDatabase.' se nám nepodařilo vybrat.'); 19 } 23 20 24 function SQLCommand($Command) 25 { // BEGIN function SQLCommand 26 $ReturnCommand = mysql_query($Command,$this->id_connection); 27 if (!$ReturnCommand) { 21 function SQLCommand($Command) 22 { 23 $ReturnCommand = mysql_query($Command, $this->id_connection); 24 if(!$ReturnCommand) 25 { 28 26 die('Nepodařilo se aplikovat příkaz.'); 29 } else { 27 } else 28 { 30 29 return $ReturnCommand; 31 30 } 32 } // END function SQLCommand31 } 33 32 34 function ReadFromDatabase($SQL) // "SELECT * FROM User" 35 { // BEGIN function ReadFromDatabase 36 $return_result = mysql_query($sql,$id_spojeni); 37 if (!$return_result) { 33 function ReadFromDatabase($SQL) 34 { 35 $return_result = mysql_query($sql, $id_spojeni); 36 if (!$return_result) 37 { 38 38 die('Nepodařilo se nám načíst řádky z databáze.'); 39 } else { 39 } else 40 { 40 41 return $return_result; 41 42 } 42 } // END function ReadFromDatabase43 } 43 44 44 45 { // BEGIN function Disconnect45 function Disconnect() 46 { 46 47 mysql_close($this->id_connection); 47 } // END function Disconnect48 } // END class Database 48 } 49 } 49 50 50 51 ?> -
includes/global.php
r40 r41 5 5 include('databaseconection.php'); 6 6 7 // připojení do databáze7 // připojení do databáze 8 8 $Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password']); 9 9 $Database->SQLCommand('SET NAMES '.$Config['Database']['Charset']); 10 10 $Database->SelectDatabase($Config['Database']['Database']); 11 11 12 // globální funkce12 // globální funkce 13 13 include('global_function.php'); 14 14 15 15 16 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">16 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 17 17 <HTML> 18 18 <HEAD> … … 37 37 38 38 '; 39 40 41 //přihlášení 42 if (array_key_exists('LoginUser',$_POST)){39 40 // přihlášení 41 if (array_key_exists('LoginUser',$_POST)) 42 { 43 43 $_SESSION['User'] = $_POST['LoginUser']; 44 44 $_SESSION['Pass'] = $_POST['LoginPass']; 45 45 46 46 $Line = mysql_fetch_array($Database->SQLCommand("SELECT * FROM user WHERE LOWER(user) = LOWER('".$_SESSION['User']."') AND pass = '".$_SESSION['Pass']."'")); 47 if (!$Line ) { 47 if (!$Line ) 48 { 48 49 echo '<script> alert("Jméno nebo heslo bylo zadáno špatně!"); </script>'; 49 50 $_SESSION['UserID'] = ''; 50 51 $_SESSION['User'] = ''; 51 52 $_SESSION['Pass'] = ''; 52 } else { 53 } else 54 { 53 55 $_SESSION['UserID'] = $Line['ID']; 54 56 $_SESSION['User'] = $Line['user']; … … 57 59 } 58 60 //odhlášení 59 if (array_key_exists('Logout',$_GET)) { 61 if (array_key_exists('Logout',$_GET)) 62 { 60 63 WriteLog('Odhlášení', 3); 61 64 $_SESSION['User'] = '';
Note:
See TracChangeset
for help on using the changeset viewer.