Hola gente, tengo un problema y no entiendo porque se produce:
Código PHP:
//Parte 1
$query='CALL playlistVote("'.$_SESSION['userid'].'","'.$_POST['id'].'","'.$_POST['num'].'");';
$db->query($query);
//Parte 2
$query='select * from channel'.$_POST['type'].' where youtube = "'.$_POST['id'].'" order by points desc limit 1';
$result=$db->query($query);
while($fila=$result->fetch_array()){
//echo formatNumber($fila['points']);
}
Al ejecutar la parte 1 todo va bien, ejecuta el procedimiento sin problema.
Al ejecutar la parte 2 si no se ha ejecutado también funciona todo correctamente.
Al ejecutar las dos, una detrás de otra me devuelve el siguiente fallo:
Fatal error: Call to a member function fetch_array() on a non-object in C:\wamp\www\TuneXperts\estructura\left\playlist-script.php on line 101
Todas las consultas de la web las realizo de la misma forma, y aquí me devuelve ese fallo, si hago un echo $query, y ejecuto la consulta directamente en Workbench me devuelve resultados sin ningún problema.
Alguien sabe a que se puede deber esto? Gracias por las respuestas.
Para más info el procedimiento que utilizo es el siguiente (Se que esta mal creado pero lo modificare cuando llegue el momento):
Código PHP:
CREATE PROCEDURE playlistVote (IN usuario int,IN idvideo varchar(11),IN val int)
begin
declare existe INT;
declare valor INT;
declare ant INT;
select count(id) into existe from musiclikes where youtube = idvideo and user = usuario;
if (existe = 0) then
insert into musiclikes(user,youtube,value) values (usuario,idvideo,val);
else
/*Borrar voto anterior*/
select value into ant from musiclikes where youtube = idvideo and user = usuario;
if(ant=0) then
update channelsongs set points = points - 1 where youtube = idvideo;
update channellive set points = points - 1 where youtube = idvideo;
update channelsessions set points = points - 1 where youtube = idvideo;
else
update channelsongs set points = points + 1 where youtube = idvideo;
update channellive set points = points + 1 where youtube = idvideo;
update channelsessions set points = points + 1 where youtube = idvideo;
end if;
update musiclikes set value = val where youtube = idvideo and user = usuario;
end if;
if(val=0) then
update channelsongs set points = points + 1 where youtube = idvideo;
update channellive set points = points + 1 where youtube = idvideo;
update channelsessions set points = points + 1 where youtube = idvideo;
else
update channelsongs set points = points - 1 where youtube = idvideo;
update channellive set points = points - 1 where youtube = idvideo;
update channelsessions set points = points - 1 where youtube = idvideo;
end if;
select val,ant;
end
//