I am trying to make a function to pull the contents of a page from a MySQL table using the PDO Prepare statement. My code works fine outside of the function that I defined, but no matter what I do, it will not work inside the function - I get the following error:
Fatal error: call prepare () member function for non-object in / home / tappess 1 / public_html / pages / stations.php on line 6
Here is my PHP:
function getPageContent($page) { $st = $db->prepare("SELECT * FROM content WHERE title LIKE ?"); $st->execute(array($page)); $pageContent = $st->fetch(); $text = wordwrap($pageContent['content'], 100, "\n"); $tabs = 4; $text = str_repeat(chr(9), $tabs) . str_replace(chr(10), chr(10) . str_repeat(chr(9), $tabs), $text); echo $text; }
and then
<?php getPageContent(Main);?>
I even tried using the query instead of the prepare statement by simply calling getPageContent () and I get the same error.
Thanks!
source share