//this is my connection.php
<?php
$pdo = new PDO('mysql:host=localhost;dbname=test;', 'root');
$pdo->exec("SET CHARACTER SET utf8");
?>
//this is my class.php
<?php
include 'connection.php';
$stmt = $pdo->prepare(query here); //wrong part
?>
problem: Error undefined $pdo, what is the right way in doing this? But when i transfer the code from the connection.php to class.php it works fine.
Declare the
$pdoasglobalin the above fileconnection.php.Check Passing a variable from one php include file to another: global vs. not and Passing variables in PHP from one file to another