linked my database to my code and attempted to connect it (database.php)
$db_name = "products_CRUD";
$db_host = 'localhost';
$username = "root";
$password = '';
$db = new PDO("mysql:dbname=$db_name;host=$db_host",$username,$password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
prepared pdo statement and executed it on a diiferent page (index.php)
<?php
/** @var $db PDO */
require_once '../../database.php';
$search = $_GET['search'] ?? null;
if($search){
$statement = $db->prepare('SELECT * FROM products WHERE title LIKE :title ORDER BY create_date DESC');
$statement->bindValue(':title',"%$search%");
}
else{
$statement = $db->prepare('SELECT * FROM products ORDER BY create_date DESC');
}
$statement->execute();
$products = $statement ->fetchALL(PDO::FETCH_ASSOC);
?>
now ends up with this error in my php server Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /Users/lani/.bitnami/stackman/machines/xampp/volumes/root/htdocs/php-crash-course-2020-master/14_product_crud/V2_better/database.php:7 Stack trace: #0 /Users/lani/.bitnami/stackman/machines/xampp/volumes/root/htdocs/php-crash-course-2020-master/14_product_crud/V2_better/database.php(7): PDO->__construct('mysql:dbname=pr...', 'root', '') #1 /Users/lani/.bitnami/stackman/machines/xampp/volumes/root/htdocs/php-crash-course-2020-master/14_product_crud/V2_better/public/products/index.php(3): require_once('/Users/lani/.bi...') #2 {main} thrown in /Users/lani/.bitnami/stackman/machines/xampp/volumes/root/htdocs/php-crash-course-2020-master/14_product_crud/V2_better/database.php on line 7