Witam, mam nastepujacy problem. Mam klase obsługującą zapytania z bazy danych. Do tego napisałem własną klase, czyszcząca zapytanie z ataku sql injection. Nie mam pojęcia jak je polaczyc, by switch, wyswietlał mi informacje z bazy danych.

Oto klasa do obslugi bazy danych w pliku mysql.class.php
  1. <?php
  2. class sqlObject {
  3. var $connection;
  4. var $database;
  5. var $query;
  6. var $result = array();
  7. var $records = array();
  8. var $queries = 0;
  9. var $lastId;
  10.  
  11.  
  12. function error() {
  13. echo '<b>'.mysql_errno().'</b> : '.mysql_error().'<br>n';
  14. }
  15.  
  16. function connect($host, $user, $password, $database, $persistent=FALSE) {
  17. $this->connection = ($persistent==TRUE) ? mysql_pconnect($host, $user, $password) : mysql_connect($host, $user, $password);
  18. if($this->connection && $database != "") {
  19. $this->database = mysql_select_db($database, $this->connection);
  20. if($this->database) {
  21. return TRUE;
  22. } else {
  23. $this->error();
  24. mysql_close($this->connection);
  25. return FALSE;
  26. }
  27. } else {
  28. $this->error();
  29. return FALSE;
  30. }
  31. }
  32.  
  33. function close() {
  34. if($this->connection) {
  35. if($this->result) mysql_free_result($this->result);
  36. mysql_close($this->connection);
  37. unset($this->query);
  38. unset($this->result);
  39. unset($this->database);
  40. unset($this->connection);
  41. return TRUE;
  42. } else $this->error();
  43. }
  44.  
  45. function query($query) {
  46. if($query!="" && $this->database) {
  47. $this->query = $query;
  48. if($this->result) mysql_free_result($this->result);
  49. if($this->result = mysql_query($this->query, $this->connection)) {
  50. $this->lastId = mysql_insert_id();
  51. $this->queries++;
  52. return $this->result;
  53. } else {
  54. $this->error();
  55. }
  56. } else $this->error();
  57. }
  58.  
  59. function fetchArray($resultHandle=0) {
  60. $this->result = ($resultHandle==0) ? $this->result : $resultHandle;
  61. if($this->database && $this->result) {
  62. $this->records = mysql_fetch_array($this->result, MYSQL_ASSOC);
  63. if(is_array($this->records)) return $this->records;
  64. else $this->error();
  65. } else $this->error();
  66. }
  67.  
  68. function fetchRow($resultHandle=0) {
  69. $this->result = ($resultHandle==0) ? $this->result : $resultHandle;
  70. if($this->database) {
  71. $this->records = mysql_fetch_row($this->result, MYSQL_ASSOC);
  72. if($this->records) return $this->records;
  73. else $this->error();
  74. } else $this->error();
  75. }
  76.  
  77.  
  78. function numRows() {
  79. if($numRows = mysql_num_rows($this->result)) return $numRows;
  80. else $this->error();
  81. }
  82. }
  83. ?>


Oto klasa wyswietlajaca zawartosc strony :
  1. <?php
  2. class wyswietlanie extends sqlObject{
  3.    var $id;
  4.    function __construct(){
  5.    $this->zmienna = $id;
  6.    $this->query;
  7.    }
  8.  
  9.    function czysc($id){
  10.    
  11.    if (get_magic_quotes_gpc()) {
  12.    }else{
  13.    $id = mysql_real_escape_string($id);
  14.    }
  15.    return $id;
  16.    }
  17.  
  18.    function zawartosc($id){
  19.    switch($id){
  20.    case 1:
  21.    $this->query("SELECT * FROM test");
  22.    echo $this->query['imie'];
  23.    while($row = $this->fetchArray()) {
  24.    echo $row['imie'].':'.$row['nazwisko'].'<br>';
  25.    }
  26.     break;
  27.    case 2: echo '<br>dwojka'; break;
  28.    default: echo '<br>default';
  29.    }
  30.    }
  31. }
  32. ?>


a tak proboje to wywołac w pliku index:
  1. <?php
  2. include('mysql.class.php');
  3. include('konfiguracja.php');
  4. include('wyswietlanie.class.php');
  5. $sql = new sqlObject;
  6. $sql->connect($host_mysql, $login_mysql, $haslo_mysql, $baza_mysql);
  7. $id = $_GET['id'];
  8. if(isset($id)){
  9. $obiekt = new wyswietlanie;
  10. echo $obiekt->zawartosc($obiekt->czysc($id));
  11.  
  12. }else {echo 'dopisz do adresu zmienna get'; }
  13. ?>


Prosze o pomoc, by skrypt wyswietlal zawartosc bazy. bo jak narazie nie ma bledu, ale wyswietla takie cos :
Kod
[b]0[/b] :
n[b]0[/b] :

ewentualnie jak zrobic to prostszym sposobem?