douzhenggui8171 2014-06-20 11:30
浏览 57
已采纳

PHP PDO bindParam()和MySQL BIT

I'm trying to update data in a table with a BIT type value in it, like the following :

// $show_contact is either '1' or '0'
$query->bindValue(':scontact', $show_contact, PDO::PARAM_INT);

The problem is, it never changes the value, it remains '1' as set on PHPMyAdmin. I tried different PDO::PARAM_ types without success, everything else is working.

edit full script

        $sql = "UPDATE users SET password = :password, address = :address, postal = :postal, city = :city, contact = :contact, show_contact = :scontact WHERE id = :id";

        $query = $dbh->prepare($sql);

        $query->bindValue(':id', $user->id, PDO::PARAM_INT);
        $query->bindValue(':password', md5($password), PDO::PARAM_STR);
        $query->bindValue(':address', $address, PDO::PARAM_STR);
        $query->bindValue(':postal', $postal, PDO::PARAM_STR);
        $query->bindValue(':city', $city, PDO::PARAM_STR);
        $query->bindValue(':contact', $contact, PDO::PARAM_STR);
        $query->bindValue(':scontact', $show_contact, PDO::PARAM_INT);
        $query->execute();
  • 写回答

2条回答 默认 最新

  • dongleiwei2182 2014-06-20 11:36
    关注

    PDO has a bit of a bug where any parameter passed to a query, even when specifically given as PDO::PARAM_INT is treated as a string and enclosed with quotes. READ THIS

    The only way to tackle it is to try the following:

    $show_contact = (int)$show_contact;
    $query->bindValue(':scontact', $show_contact, PDO::PARAM_INT);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog