我收到以下消息:
Notice: Undefined variable: dbh in /var/www/PDO/Functions/PDOFunctions.php on line 12 Fatal error: Call to a member function prepare() on a non-object in /var/www/PDO/Functions/PDOFunctions.php on line 12
$dbh = new PDO('mysql:host=localhost;dbname=pdo', 'root', 'xxxxxxxxxxx');
global $dbh;
function PDOFetch($Var)
{
$sth = $dbh->prepare("$Var"); //Error Line
$sth->execute();
$result = $sth->fetchAll();
return $result;
}
function PDONumb ($Var)
{
$Query = $dbh->prepare("{$Var}");
$Execute->execute();
$count = $Execute->rowCount();
return $count;
}
什么是我的代码的问题?
'global $ dbh'进入函数内部。 –
看看我的简单[DByte库](https://github.com/Xeoncross/DByte)。 – Xeoncross
问题是你不知道'global'是如何工作的。你应该用google搜索并阅读文档,然后再问Stack Overflow的问题...... – meagar