Home  >  Q&A  >  body text

pdo_mysql 值自增写法

以前用mysql_query的时候,为了实现数据库计数,是使用

mysql_query("update table set field=field+1 where ....");

这种方式,现在整体换成pdo_mysql的话,

("update table set field=? where ....")

然后?处bind field+1肯定是不行了...

怎么写自增效率较高呢?请教下各位,感谢

黄舟黄舟2742 days ago663

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 15:32:59

    Ah, isn’t there a query method?

    $pdo = new \PDO($dsn, $user, $password);
    $pdo->query("update table set field=field+1 where ....");

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 15:32:59

    It’s okay if you don’t need parameter substitution in this place... just write field=field+1

    reply
    0
  • Cancelreply