使用PDO进行Big UPDATE查询

时间:2014-07-21 10:59:35

标签: php mysql pdo

我正在尝试使用UPDATE编写PDO查询,但我无法执行我的代码。 这是和UPDATE函数,它按orderID更新特定行。有什么想法吗?

function UpdateExistingEvent ($oID, $title, $range, $organizer, $chief,
$secretary, $coOrganizer, $shortDesc, $poster, $datebegin, $dateend, 
$room, $roomEquipment, $cardHolterAmount, $cardHolderNames) {
  try
  {   
    $obj=new DBconnection();
    $dhb=$obj->db_connect();   
    $sql = 'UPDATE `materialy.event` SET '
            . '`title` = :title,'
            . '`range` = :range, '
            . '`organizer` = :organizer, '
            . '`chief` = :chief, '
            . '`secretary` = :secretary, '
            . '`coOrganizer` = :coOrganizer, '
            . '`shortDesc` = :shortDesc, '
            . '`poster` = :poster, '
            . '`dateBegin` = :dateBegin, '
            . '`dateEnd` = :dateEnd, '
            . '`room` = :room, '
            . '`roomEquipment` = :roomEquipment, '
            . '`cardHolderAmount` = :cardHolderAmount, '
            . '`cardHolderNames` = :cardHolderNames '
            . 'WHERE `orderID` = :orderID';   
    $stmt = $dhb->prepare($sql);

    $stmt ->bindParam(':title', $title, PDO::PARAM_STR);
    $stmt ->bindParam(':range', $range, PDO::PARAM_STR);
    $stmt ->bindParam(':organizer', $organizer, PDO::PARAM_STR);
    $stmt ->bindParam(':chief', $chief, PDO::PARAM_STR);
    $stmt ->bindParam(':secretary', $secretary, PDO::PARAM_STR);
    $stmt ->bindParam(':coOrganizer', $coOrganizer, PDO::PARAM_STR);
    $stmt ->bindParam(':shortDesc', $shortDesc, PDO::PARAM_STR);
    $stmt ->bindParam(':poster', $poster, PDO::PARAM_STR);
    $stmt ->bindParam(':dateBegin', $datebegin, PDO::PARAM_STR);
    $stmt ->bindParam(':dateEnd', $dateend, PDO::PARAM_STR);
    $stmt ->bindParam(':room', $room, PDO::PARAM_INT);
    $stmt ->bindParam(':roomEquipment', $roomEquipment, PDO::PARAM_STR);
    $stmt ->bindParam(':cardHolderAmount', $cardHolterAmount, PDO::PARAM_INT);
    $stmt ->bindParam(':cardHolderNames', $cardHolderNames, PDO::PARAM_STR);
    $stmt ->bindParam(':orderID', $oID, PDO::PARAM_STR);


    $stmt->execute();
    $stmt->debugDumpParams();

    if( $stmt->rowCount() )
    {
        echo '<div id="GAlert" class="CompleteAlertCentral">Complete!</div>';
    }
    else
    {
        echo '<div id="error">error!<div>';
    }

  }
  catch(PDOException $e){
     echo 'PDO Library Error: '.$e->getMessage();
  }

}

我不知道出了什么问题。 INSERTREAD效果很好,但UPDATE没有。请帮帮我。

1 个答案:

答案 0 :(得分:1)

您的问题可能就在这一行:

UPDATE `materialy.event` SET

除非你的表名中有句号(这是可能的,但通常不太可能)。你可能意味着:

UPDATE `materialy`.`event` SET