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
<?php
class sqlObject {
var $connection;
var $database;
var $query;
var $queries = 0;
var $lastId;
function error() {
}
function connect($host, $user, $password, $database, $persistent=FALSE) {
if($this->connection && $database != "") {
if($this->database) {
return TRUE;
} else {
$this->error();
return FALSE;
}
} else {
$this->error();
return FALSE;
}
}
function close() {
if($this->connection) {
unset($this->connection); return TRUE;
} else $this->error();
}
function query($query) {
if($query!="" && $this->database) {
$this->query = $query;
if($this->result = mysql_query($this->query, $this->connection)) { $this->queries++;
return $this->result;
} else {
$this->error();
}
} else $this->error();
}
function fetchArray($resultHandle=0) {
$this->result = ($resultHandle==0) ? $this->result : $resultHandle;
if($this->database && $this->result) {
if(is_array($this->records)) return $this->records; else $this->error();
} else $this->error();
}
function fetchRow($resultHandle=0) {
$this->result = ($resultHandle==0) ? $this->result : $resultHandle;
if($this->database) {
if($this->records) return $this->records;
else $this->error();
} else $this->error();
}
function numRows() {
else $this->error();
}
}
?>
Oto klasa wyswietlajaca zawartosc strony :
<?php
class wyswietlanie extends sqlObject{
var $id;
function __construct(){
$this->zmienna = $id;
$this->query;
}
function czysc($id){
}else{
}
return $id;
}
function zawartosc($id){
switch($id){
case 1:
$this->query("SELECT * FROM test");
echo $this->query['imie']; while($row = $this->fetchArray()) {
echo $row['imie'].':'.$row['nazwisko'].'<br>'; }
break;
case 2
: echo '<br>dwojka'; break; default: echo '<br>default'; }
}
}
?>
a tak proboje to wywołac w pliku index:
<?php
include('mysql.class.php');
include('konfiguracja.php');
include('wyswietlanie.class.php');
$sql = new sqlObject;
$sql->connect($host_mysql, $login_mysql, $haslo_mysql, $baza_mysql);
$id = $_GET['id'];
$obiekt = new wyswietlanie;
echo $obiekt->zawartosc($obiekt->czysc($id));
}else {echo 'dopisz do adresu zmienna get'; } ?>
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?
Powód edycji: Poprawiłem bbCode (ociu)