I am creating a class for manipulation of the DB, and am having problems in the use of "saida" function. This function returns me the "Array" from the DB. The problem is that when I call the function it does not print the values.
Help me please!!
classmydb.inc
<?php
class mybd
{
var $host="localhost";
var $user="emanuel";
var $senha="esf0891";
var $base="sms";
var $results;
var $line;
var $total;
var $capsula;
function conecta(){
$this->conecta = mysql_connect($this->host,$this->user,$this->senha);
if($this->conecta){
mysql_selectdb($this->base);}
else {
$this->conecta = 0;
}
{
return $this->conecta;
}
}
function executa($query){
$this->results = mysql_query($query) or die(mysql_error());
{
return $this->results;
}
if(substr($query,0,6)=="select")
$this->total = mysql_num_rows($this->results);
}
function first(){
$this->line = 0;
$this->saida();
}
function foward(){
$this->line = ($this->line<($this->total - 1))? ++$this->line : ($this->total - 1);
$this->saida();
}
function back(){
$this->line = ($this->line>0)? -$this->line : 0;
$this->saida();
}
function last(){
$this->line = $this->total-1;
$this->saida();
}
function gerencia($atual){
if($atual>=0 and $atual<$this->line){
$this->line = $atual;
$this->saida();
}
function saida(){
mysql_data_seek($this->results,$this->line);
$this->capsula = mysql_fetch_array($this->results)or die(mysql_error());
{
return $this->capsula;
}
}
}
}
?>
displayer.php
<?php
//carrega as respectivas classes.
require_once("classmydb.inc");
//cria nova instancia de classe.
$data = new mybd();
//cria conexão com o banco de dados.
if(!$data->conecta()){
echo "Não foi possível conectar ao bd!";
exit;
}
//faz a consulta no bd.
$query = "select * from imagem";
//cria nova instancia para classe.
if(!$data->executa($query)){
echo "Não possível executar a instrução sql";
}
//executa instrução sql no bd.
while ($teste=$data->capsula){
echo " $teste[nome] $teste[categoria]" ;
}
echo "ok";
?>