Well, folks, I'm now switching to PDO in php, I wanted your opinion to know if the method I'm programming is safe and if I'm programming PDO in the right way because I saw on the internet several ways to program
Example code of how I am doing
<?php
$result_cat = $conexao->query("SELECT * FROM categorias WHERE menu='home' AND activo=1");
$row_cat = $result_cat->fetch(PDO::FETCH_OBJ);
$result_capa = $conexao->query("SELECT * FROM categorias_anexos WHERE id_mae='".$row_cat->id."' AND seccao='capa'");
$row_capa = $result_capa->fetch(PDO::FETCH_OBJ);
?>
Connection to the bank
$host = "localhost";
$bd = "sabeonde_sabeonde";
$user = "[USUARIO]";
$pass = "[SENHA]";
try {
$conexao = new PDO('mysql:host='.$host.';dbname='.$bd.';charset=utf8', ''.$user.'', ''.$pass.'');
$conexao->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Error : <br>' . $e->getMessage();
}
Test
$result_capa = $conexao->prepare("SELECT * FROM categorias_anexos WHERE id_mae = :row_cat AND seccao='capa'");
$result_capa = bindParam(":row_cat", $row_cat->id, PDO::PARAM_INT);
$result_capa->execute();
$row_capa = $result_capa->fetch(PDO::FETCH_OBJ);