0
I would like your help to transform the following code to PHP PDO.
I made the following conversions and commented on the front of the code, just to answer the question. It is if the conversion is correct?
<?php
function retorna($cod_material, $conn){
$result_aluno = "SELECT nome FROM lista_geral WHERE cod_material = '$cod_material' LIMIT 1";
$resultado_aluno = mysqli_query($conn, $result_aluno);
//$resultado_aluno = $pdo->query($conn, $result_aluno); //CONVERTIDO
if($resultado_aluno->num_rows){
$row_aluno = mysqli_fetch_assoc($resultado_aluno);
//$row_aluno = PDO::FETCH_ASSOC($resultado_aluno); //CONVERTIDO
$valores['nome'] = $row_aluno['nome'];
}else{
$valores['nome_aluno'] = 'Aluno não encontrado';
}
return json_encode($valores);
}
if(isset($_GET['cod_material'])){
echo retorna($_GET['cod_material'], $conn);
}
?>
Here and to answer questions and not make codes for you, study about PDO, see videos, read books and handouts and you will get, with effort and dedication
– Victor
You are demonstrating that you copied and pasted this code here, who knows how to program in php easily understand Pdo I’m sorry, but I will try to help you yes
– Victor
That code there is wrong, here can convert from
mysql_
for the PDO.– rray