PHP PDO执行挂起执行

When working with a PHP PDO, calling execute on a prepared statement appears to completely hang the execution of the script. The PDO is initialized as follows:

$db = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_PERSISTENT, false);

As far as I know, the connection works fine- there is no indication given that it fails. Then, later, I call prepare and then execute, and the execution appears to halt.

echo "Hi";                                                      //executes
$username = mysql_real_escape_string($_POST['username']);
echo "Still Here";                                              //executes
$password = md5(mysql_real_escape_string($_POST['password']));
echo "So far so good";                                          //executes
$stmt = $db->prepare("SELECT * FROM users WHERE Username=:username");
echo "Still good";                                              //executes
$stmt.execute(array(':username' => $username));
echo "Nope...";                                             //doesn't execute
if($stmt->rowCount() >= 1)
{
    echo "Sorry, that username is already taken.";
}

I am not sure what exactly is happening that causes this error, however any help in fixing it would be appreciated.

you have missed -> by . in execute line.

replace

$stmt.execute(array(':username' => $username));

by $stmt->execute(array(':username' => $username));

you can use binding. you don't need to use mysql_real_escape_string in PDO

mysql_real_escape_string needs a mysql connection,which is not there,since you are connecting with PDO,so your function doesn't do anything.

Besides,WHY are you not using only prepared statements?