dpqaaczn141761 2014-02-13 18:31
浏览 44
已采纳

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.

  • 写回答

2条回答 默认 最新

  • dongzhi1822 2014-02-13 18:33
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解