I trying to run my query but everytime I try to run it, it would give me this kind of error: Call to a member function fetchAll() on a non-object.
this is my code:
Single.php:
<?php
require 'admin/config.php';
require 'functions.php';
$conexion = conexion($db_config);
$url_canal = url_canal($_GET['url']);
if (!$conexion) {
header('Location: error.php');
}
if (empty($url_canal)) {
header('Location: index.php');
}
$canal = obtener_canal_por_url($url_canal, $conexion);
if(!$canal) {
header('Location: index.php');
}
$canal = $canal[0];
require 'views/single.view.php';
?>
functions.php:
function limpiarDatos($datos) {
$datos = trim($datos);
$datos = stripslashes($datos);
$datos = htmlspecialchars($datos);
return $datos;
}
function url_canal($url) {
return limpiarDatos($url);
}
function obtener_canal_por_url($url, $conexion) {
$resultado = $conexion->query("SELECT * FROM canales WHERE url = $url LIMIT 1");
$resultado = $resultado->fetchAll();
return ($resultado) ? $resultado : false;
}
Can you help me to solve this, please? i want to know where is my mistake. Thank you
Conexion:
function conexion($db_config) {
try {
$conexion = new PDO('mysql:host=localhost;dbname='. $db_config['bd'], $db_config['usuario'], $db_config['pass']);
return $conexion;
} catch (PDOException $e) {
return false;
}
}