0
I’m creating a system of Likes and currently he was connecting with Mysql, then now I’m migrating to Mysqli, but is giving an error and I can not solve at all :(
php connection.
<?php
$servidor = 'localhost';
$usuario = 'root';
$senha = '';
$banco = 'meu_banco';
$con = mysqlI_connect($servidor, $usuario, $senha, $banco);
?>
php function.
<?php
function get_artigos(){
$artigos = array();
$selecionar = "SELECT artigo_id, titulo, likes FROM artigos";
while ($row->mysqli_fetch_object($selecionar)){
$artigos[] = array(
'id_artigo' => $row->artigo_id,
'titulo' => $row->titulo,
'likes' => $row->likes
);
}
return $artigos;
}
function verificar_clicado($id_artigo, $id_usuario){
$id_artigo = (int)$id_artigo;
$id_usuario = (int)$id_usuario;
$verificar = "SELECT like_id FROM likes WHERE user_id = '$id_usuario' AND artigo_id = '$id_artigo'");
return (mysql_num_rows($verificar) >= 1) ? true : false;
}
function adicionar_like($id_artigo, $id_usuario){
$id_artigo = (int)$id_artigo;
$id_usuario = (int)$id_usuario;
$atualizar_likes_post = "UPDATE artigos SET likes = likes+1 WHERE artigo_id = '$id_artigo'";
if($atualizar_likes_post){
$inserir_like = "INSERT INTO likes (user_id, artigo_id) VALUES ('$id_usuario','$id_artigo'");
if($inserir_like){
return true;
}else{
return false;
}
}
}
function retornar_likes($id_artigo){
$id_artigo = (int)$id_artigo;
$selecionar_num_likes = "SELECT likes FROM artigos WHERE artigo_id = $id_artigo";
$fetch_likes = mysqli_fetch_object($selecionar_num_likes);
return $fetch_likes->likes;
}
?>
mysqlI_connect
, switches to small letter... What error gives?– Sergio
I think only changing mysqli to mysqli already works, as Sergio said, because the mysqli command works the same way as mysql, but it accepts a wider range of services and options
– Murilo Melo
tip* Don’t put your connection parameters where everyone can see, always make it look like you’re going to use the test pattern on the pc. Ex: ('localhost', 'root', ', 'local_db')
– Murilo Melo
@Murilogambôa thanks for the tip, I put the i in minusculo but the same error keeps appearing :(
– Jessica Cardoso Rogoski
Where is the error?
– viana