yakczh
V2EX  ›  PHP

pdo 绑定参数为什么要从 1 开始

  •  
  •   yakczh · Jul 17, 2015 · 2569 views
    This topic created in 3979 days ago, the information mentioned may be changed or developed.

    $calories = 150;
    $colour = 'red';
    $sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < ? AND colour = ?');
    $sth->bindValue(1, $calories, PDO::PARAM_INT);
    $sth->bindValue(2, $colour, PDO::PARAM_STR);
    $sth->execute();

    maxsec
        1
    maxsec  
       Jul 17, 2015
    why not try:

    $sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < :calories AND colour = :colour');
    $sth->bindValue(':calories', $calories, PDO::PARAM_INT);
    $sth->bindValue(':colour', $colour, PDO::PARAM_STR);
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3745 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:34 · PVG 12:34 · LAX 21:34 · JFK 00:34
    ♥ Do have faith in what you're doing.