我在名称间隔的部分中遇到了全局名称空间的问题。这意味着,当我执行下面的功能时,我得到了
Fatal error: Uncaught Error: Class 'login\PDO' not found in /var/www/html/easyboard/scripts/php/functions.php:12 Stack trace: #0 /var/www/html/easyboard/users/login/login.php(42): login\checkUser('cripi') #1 /var/www/html/easyboard/index.php(8): require_once('/var/www/html/e...') #2 {main} thrown in /var/www/html/easyboard/scripts/php/functions.php on line 12
代码:
<?php
namespace login {
#------------------------
#check do user exists
function checkUser($username)
{
$username = strtolower($username);
global $pdo;
global $login;
$statement = "SELECT * FROM " . $login['tableName'] . " WHERE username = :username OR email = :email;";
$statement = $pdo->prepare($statement);
$statement->bindValue(':username', $username, PDO::PARAM_STR);
$statement->bindValue(':email', $username, PDO::PARAM_STR);
if ($statement->execute()) {
if ($statement->rowCount() >= 1) {
return true;
} else {
return false;
}
} else {
return false;
}
}
// Cripi