_pdo = new PDO ($connectionString, $g_User, $g_Password); } catch ( PDOException $e ) { echo "Echec de la connexion: ".$e->getMessage()."
"; die(); } } function __destruct() { $this->_pdo = null; } /** * retourne la collection (un tableau simple) de tous les tickets * (le tableau retourné peut être vide.) */ function findAll() { $result = array (); // TODO return $result; } /** * retourne l'instance de Ticket d'ID $searchedTicketId * (ou null si le ticket n'est pas trouvé) */ function findById($searchedTicketId) { $result = null; $query = "SELECT $this->COLUMN_NAMES FROM $this->TABLE_NAME WHERE ticketID = ?"; $stmt = $this->_pdo->prepare($query); $stmt->bindParam(1, $searchedTicketId); if ( !$stmt->execute() ) { echo "Error calling findById() : "; print_r($stmt->errorInfo()); } $row = $stmt->fetch(); if ( $row ) { list ($ticketID, $applicationName, $login, $priority, $type, $creationDate, $oneLiner, $detailedDescription, $attachmentName) = $row; $newTicket = new Ticket($applicationName, $login, $priority, $type, $creationDate, $oneLiner, $detailedDescription, $attachmentName, $ticketID); $result = $newTicket; } $stmt = null; $stmt->closeCursor(); return $result; } /** * sauve $ticket dans la base */ function save(Ticket $ticket) { if ( $ticket->getTicketID() == -1 ) return $this->insert($ticket); else return $this->update($ticket); } /** * insère $ticket comme un nouvel enregistrement */ function insert(Ticket $ticket) { // TODO } /** * met à jour l'enregistrement d'id $ticket->ticketID à partir de $ticket */ function update(Ticket $ticket) { $ticketID = $ticket->getTicketID(); $applicationName = $ticket->getApplicationName(); $login = $ticket->getLogin(); $priority = $ticket->getPriority(); $type = $ticket->getType(); $creationDate = $ticket->getCreationDate(); // protéger les caractères guillemets $oneLiner = addslashes($ticket->getOneLiner()); $detailedDescription = addslashes($ticket->getDetailedDescription()); $updatequery =<<TABLE_NAME SET applicationName = :applicationName, login = :login, priority = :priority, type = :type , creationDate = :creationDate, oneLiner = :oneLiner, detailedDescription = :detailedDescription, attachmentName = :attachmentName WHERE ticketID = :ticketID; EOT; $stmt = $this->_pdo->prepare($updatequery); $stmt->bindParam(':applicationName', $applicationName); $stmt->bindParam(':login', $login); $stmt->bindParam(':priority', $priority); $stmt->bindParam(':type', $type); $stmt->bindParam(':creationDate', $creationDate); $stmt->bindParam(':oneLiner', $oneLiner); $stmt->bindParam(':detailedDescription', $detailedDescription); $stmt->bindParam(':attachmentName', $attachmentName); $stmt->bindParam(':ticketID', $ticketID); if ( !$stmt->execute() ) { echo "Error calling insert() : "; print_r($stmt->errorInfo()); } $stmt->closeCursor(); } function deleteAll() { $deletequery = 'DELETE FROM ' . $this->TABLE_NAME; $this->_pdo->exec($deletequery); if ( $this->_pdo->errorCode() != 0 ) { echo "Error calling delete() : " ; print_r($stmt->errorInfo()); } } } ?>