5
I’m creating a class that fetches data from the database for display. For example, one of the functions of the class is to take the date, of a given, in the database and display on the screen. The way I’m doing, it’s not working.
Follows my code
<?php
class contaEntrada {
var $dataConta;
var $descricaoConta;
var $valorConta;
function conectar(){
$host = "localhost";
$user = "root";
$pass = "root";
$dbname = "fluxo_de_caixa";
try {
$opcoes = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$pdo = new PDO("mysql:host=localhost;dbname=fluxo_de_caixa;", "root", "root", $opcoes);
} catch (Exception $e) {
echo $e->getMessage();
}
return $pdo;
}
function pegaDataConta(){
$pdo = conectar();
$pegaData=$pdo->prepare("SELECT data FROM entrada WHERE id_entrada:id");
$pegaData->bindValue(":id", 30);
$pegaData->execute();
}
function mostraConta(){
echo $this->descricaoConta = "Conta de luz";
}
function valorConta(){
echo $this->valorConta = "50,00";
}
}
And I’m calling the functions in another file. index php.
<?php
require_once "con/conexao.php";
require_once "classes/contaEntrada.php";
$entrada = new contaEntrada();
$entrada->pegaDataConta();
echo " - ";
$entrada->mostraConta();
echo " - ";
$entrada->valorConta();
id_entrada = :id
and after the run, you could use the method fetch to return the set referring to this query.– Edilson