yakczh
V2EX  ›  PHP

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

  •  
  •   yakczh · Jul 17, 2015 · 2535 views
    This topic created in 3955 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   ·   5566 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 07:14 · PVG 15:14 · LAX 00:14 · JFK 03:14
    ♥ Do have faith in what you're doing.