//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
?>
问题:错误未定义 $pdo,这样做的正确方法是什么?但是当我将代码从 connection.php 传输到 class.php 时,它工作正常。