I'm new to PDO so please bear with me. I'm trying to convert my old mysql to PDO but I am getting a "Fatal error: Call to a member function prepare() on a non-object in functions.php on line 5".
So this is functions.php:
<?php
require('config.php');
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
function getSlug($param){
$sth = $conn->prepare("SELECT * FROM articles WHERE slug = ?");
$sth->execute(array($param));
$slug = $sth->fetchAll(PDO::FETCH_ASSOC);
return $slug;
}
?>
And this is page that generates the error:
<?php
include('functions.php');
$param = $_GET['param'];
$slug = getSlug($_GET['param']);
?>
It seems like it's the last line $slug = getSlug($_GET['param']);
that's causing the issue but I can't work it out, or it might be something elsewhere.
Thanks