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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器