I get a couple of mistakes and I canβt see for life where I fall. Below is the function file
<?php include('config.php'); function getAllPosts() { try { $dbh = new PDO(DB_HOST, DB_USER, DB_PASS); } catch (PDOException $e) { echo $e->getMessage(); } $stmt = $dbh->prepare('SELECT id, title, content FROM posts ORDER BY created_at DESC'); $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); return $results; } function getSinglePost($id) { try { $dbh = new PDO(DB_HOST, DB_USER, DB_PASS); } catch (PDOException $e) { echo $e->getMessage(); } $stmt = $dbh->prepare('SELECT title, content FROM posts WHERE id = ?'); $bindings = array($id); $stmt->execute($bindings); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result; } ?>
Also decided that I should include the page that I am launching in order to cause an error
<?php include('system/functions.php'); ?> <html> <head> <title>Create A New Post | My First Blog</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="form"> <?php if (isset($_GET['id'])){ ?> <h2>Single Post:</h2> <?php $post = getSinglePost($_GET['id']); ?> <?php print_r($post); ?> <?php } ?> <fieldset> </fieldset> </div> </body> </html>
Any help is much appreciated, these are errors in their entirety.
Note: using the undefined DB_HOST constant - it is assumed that DB_HOST in C: \ xampp \ htdocs \ blog \ system \ functions.php on line 31
Note: using the undefined constant DB_USER - it is assumed that DB_USER is in C: \ xampp \ htdocs \ blog \ system \ functions.php on line 31
Note: using the undefined DB_PASS constant - it is assumed that DB_PASS in C: \ xampp \ htdocs \ blog \ system \ functions.php on line 31 is an invalid data source name Note: undefined variable: dbh in C: \ xampp \ htdocs \ blog \ system \ functions.php on line 37
Fatal error: call prepare () member function for object in C: \ xampp \ htdocs \ blog \ system \ functions.php on line 37
Must also include a configuration file
<?php define('DB_HOST','mysql:host=localhost;dbname=blog'); define('DB_USER','root'); define('DB_PASS',''); ?>