0

在下面的代码中,我试图通过计算用户名来检查输入的用户名是否已被使用。

<?php
$hostname = 'aaa';
$username = 'bbb';
$password = 'ccc';
$prefix = "";
$dbna = 'ddd';
$username11 = $_POST['username'];
try {
$dbh = new PDO("mysql:host=$hostname;dbname=$dbna", $username, $password);
$nRows = $pdo->query("SELECT count(Username) FROM Users WHERE Username ='$username11'")->fetchColumn(); 
if($nRows)
{
echo '<span style="color: red;">The username <b>'.$username11.'</b> is already in use.    </span>';
}
else
{
echo 'OK';
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>

错误是:

Fatal error: Call to a member function query() on a non-object in /home/check.php on line 10

我寻找此错误的解决方案,但找不到。

4

1 回答 1

2
$pdo->query

应该:

$dbh->query
于 2012-07-04T01:05:08.807 回答