I am creating a class that looks for database data to be displayed. For example, one of the functions of the class is to pick the date, from a die, in the bank and display it on the screen. The way I'm doing, it's not working.
Follow 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();