I'm getting the following message:
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;
}
What is the problem with my code?
global $dbhgoes inside the functions. - Tim Cooperglobalworks. You should have googled this and read the documentation before asking a question on Stack Overflow... - meagar