I have connection.php file as :
<?php
       $dsn='mysql:host=localhost;dbname=sakila';
   $hostname='localhost';
   $username='root';
   $password='';
    $PDO_ob = new PDO($dsn, $username, $password);
   try {
        $PDO_ob = new PDO($dsn, $username, $password);
        $PDO_ob->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          echo " connection success";
    } catch (PDOException $ex) {
        echo 'Connection failed: ' . $ex->getMessage();
    }
   ?>  
And functions.php  as :
    <?php 
    include "../category_prodct_pdo/connection.php";
    function get_products(){
        global $PDO_ob;
        $sql="SELECT * FROM products";
        $products=$PDO_ob->query($sql); 
        return $products;
    }
    ?>
When I delete the line glopal $PDO_op; I receive n error message " Undefined variable: PDO_ob " I know that using global variables in functions is not the best implement so how can make this work without to use global inside the function Thank You in Advance
 
    