I made an OO code in PHP. I used MySQLi for the database and WAMPSERVER as the server, where I inserted data into the "category" table. The bank collation is "latin2_general_ci". There were no errors, but in the browser the data entered did not appear. Below is the code:
<?php
$conecta = new mysqli("localhost", "root", "", "teste_forum");
if($conecta->connect_error){
die("Connection failed: " . $conecta->connect_error);
}
class categoria{
private $id;
private $titulo;
/*public function conexao($conecta){
$conecta = new mysqli("localhost", "root", "", "teste_forum");
}*/
public function setId($id){
$this->id = $id;
}
public function getId(){
return $this->id;
}
public function setTitulo($titulo){
$this->titulo = $titulo;
}
public function getTitulo(){
return $this->titulo;
}
function listar(categoria $categoria){
try{
global $conecta;
$query = $conecta->query("SELECT titulo FROM categoria");
return $query;
/*$rs = $query->fetch_assoc();
$categoria->setTitulo($rs["titulo"]);*/
}
catch(Exception $e){
echo "ERRO!";
}
}
function inserir(categoria $categoria){
try{
global $conecta;
$query = $conecta->prepare("INSERT INTO categoria (titulo) VALUES (?)") or die ($conecta->error);
$query->bind_param("s", getTitulo());
$query->execute();
if ($query->affected_rows > 0){
return true;
}
}
catch(Exception $e){
echo "ERRO!";
}
}
}
?>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
h3{
color: red;
}
h4{
color: steelblue;
}
form{
border: 1px #333 solid;
}
.nome{
color: green;
}
.coment{
color: violet;
}
</style>
</head>
<body>
<?php
$categoria = new Categoria;
$cat_listar = $categoria->listar($categoria);
while($reg = $cat_listar->fetch_array()){
echo "<h3>......... " . $categoria->getTitulo($reg["titulo"]) . ".........</h3>";
}
?>
<br><br>
<a href="form.php">Ir ao formul�rio cadastrar categorias</a>
In the figure below, I would like the browser to show the titles.
Andtheotherfigurebelowshowstheresult.Thetitleshadtobeinthereddots.
All I want is for the titles to be displayed.