There are a lot of questions with this error. I've read all of them but none of them resolves my problem. Their problems are totally differents, that's why I'm asking.
I'm getting this error: Fatal error: Call to a member function query() on a non-object
.
It's on line $conexion->query($consulta);
.
I've checked if the connection object ($conexion
) is null and it's not, it's correctly filled with the connection.
I've also tried to make a custom default query (just in case the query wasn't correct) but I'm still having the problem.
So, what's going on here?
This is my code:
<?php
function conectar(){
$data = include_once('configDB.php');
$c = mysql_connect($data["server"], $data["user"], $data["pass"]);
if ($c)
return $c;
else
exit("fail");
}
function insertar($nombre, $resultados, $tiempo){
$conexion = conectar();
$consulta = "INSERT INTO juegopreguntas (nombre, p1, p2, p3, p4, p5, tiempo) VALUES
('".$nombre."',".$resultados[0].",".$resultados[1].",".$resultados[2].",".$resultados[3]
.",".$resultados[4].",'".$tiempo."')";
$conexion->query($consulta);
cerrarConexion($conexion);
}
function cerrarConexion($conexion){
mysql_close($conexion);
}
?>