Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2.    
  3.     define('DB_HOST', 'localhost'); # host bazy danych
  4.     define('DB_PORT', 3306); # port bazy danych
  5.     define('DB_USER', ''); # użytkownik bazy danych
  6.     define('DB_NAME', ''); # nazwa bazy danych
  7.     define('DB_PASS', ''); # hasło bazy danych
  8.  
  9.     class Database
  10.     {
  11.  
  12.         private $host = DB_HOST;
  13.         private $user = DB_USER;
  14.         private $pass = DB_PASS;
  15.         private $dbname = DB_NAME;
  16.        
  17.         function __construct()
  18.         {  
  19.        
  20.             $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
  21.      
  22.             $options = array(
  23.                 PDO::ATTR_PERSISTENT    => true,
  24.                 PDO::ATTR_ERRMODE       => PDO::ERRMODE_EXCEPTION
  25.             );
  26.  
  27.             try{
  28.                 $this->db = new PDO($dsn, $this->user, $this->pass, $options);
  29.             }
  30.  
  31.             catch(PDOException $e){
  32.                 exit('Brak polaczenia z baza danych.');
  33.             }
  34.        
  35.         }
  36.     }
  37.    
  38.     class Tools extends Database
  39.     {
  40.         public function Records( $default )
  41.         {
  42.             $query = $this->db->prepare("SELECT * FROM `mecze` WHERE `league_id`= :league_id");
  43.             $query->bindValue(':league_id', $default, PDO::PARAM_INT);
  44.             $query->execute();
  45.             $list = $query->fetchAll(PDO::FETCH_ASSOC);
  46.             $query->closeCursor();
  47.         }
  48.        
  49.         public function Update( $title, $logo, $status, $points_plus, $done_matches, $points2_plus, $points2_minus, $diff, $league_id )
  50.         {
  51.             $query = $this->db->prepare( 'UPDATE `mecze` SET `title` = :title WHERE `id`= :userid' );
  52.             $query->bindValue( ':title', $title, PDO::PARAM_STR );
  53.             $query->bindValue( ':logo', $logo, PDO::PARAM_STR );
  54.             $query->bindValue( ':status', $status, PDO::PARAM_STR );
  55.             $query->bindValue( ':points_plus', $points_plus, PDO::PARAM_STR );
  56.             $query->bindValue( ':done_matches', $done_matches, PDO::PARAM_STR );
  57.             $query->bindValue( ':points2_plus', $points2_plus, PDO::PARAM_STR );
  58.             $query->bindValue( ':points2_minus', $points2_minus, PDO::PARAM_STR );
  59.             $query->bindValue( ':diff', $diff, PDO::PARAM_STR );
  60.             $query->bindValue( ':league_id', $league_id, PDO::PARAM_STR );
  61.             $query->execute();
  62.             $count = $query->rowCount();
  63.             $query->closeCursor();
  64.            
  65.             if($count > 0) return true;
  66.         }
  67.     }
  68.    
  69.     // zastosowanie Records
  70.    
  71.     foreach( $obiekt->Records(6) as $var )
  72.     {
  73.         print_r($var);
  74.     }
  75.    
  76.    
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement