_db = $db; } /** Retourne la valeur de la variable $_idportable */ function getIdportable() { return $this->_idportable; } /** Change la valeur de la variable $_idportable */ function setIdportable($idportable) { $this->_idportable = intval($idportable); } /** Retourne la valeur de la variable $_idtxt */ function getIdtxt() { return $this->_idtxt; } /** Change la valeur de la variable $_idtxt */ function setIdtxt($idtxt) { $this->_idtxt = $idtxt; } /** * Gestion d'erreur * @param $error Message d'erreur */ function error($error) { $this->lasterror = $error; } /** * Création de la table * @pre : la table n'existe pas * @post : la nouvelle table est crée */ function createTable() { $sql = 'CREATE TABLE inv_portable ( idportable int(11) PRIMARY KEY AUTO_INCREMENT, idtxt varchar(10) NOT NULL default \'\' )'; if (!mysql_query($sql,$this->_db)) { $errno = mysql_errno(); if ($errno == 1050) { echo 'This mysql table already exists, please remove createTable() method call or drop the table first.'; } else { $this->error(mysql_error($this->_db)); } } } /** * Supprime la table * @pre : la table existe * @post : la table et tous les enregistrements sont effacés */ function dropTable() { $sql = 'DROP TABLE inv_portable'; $qry = mysql_query($sql,$this->_db) or $this->error(mysql_error($this->_db).' : '.$sql); } /** * Supprime un element avec son $id * @pre : l'enregistrement avec le numero $id existe * @post : l'enregistrement avec le numero $id est effacé */ function deleteItem($id) { if ( is_numeric($id) ) { $sql = 'DELETE FROM inv_portable WHERE idportable='.$id; $qry = mysql_query($sql,$this->_db) or $this->error(mysql_error($this->_db).' : '.$sql); } } /** * Permet d'optenir un enregistrement, à l'aide d'un id * @param $ib ID de la ressource */ function getItem($id) { $sql = 'SELECT idportable, idtxt FROM inv_portable WHERE idportable=\''.$id.'\''; if ( $qry = mysql_query($sql, $this->_db) ) { if ( $obj = mysql_fetch_object($qry) ) { $this->_idportable=$obj->idportable; $this->_idtxt=stripslashes($obj->idtxt); } else { $this->_idportable=0; } } } /** * Insère un nouvel élément dans la liste * @pre : la table existe avec les bons champs * @pre : tous les parametres ont été correctement configurés * @post : il y a un nouvel enregistrement * @return le numero (id) de l'enregistrement ou null */ function insertItem() { $returnValue = 0; $sql = 'INSERT INTO inv_portable (idtxt) VALUES (\''.mysql_real_escape_string($this->_idtxt, $this->_db).'\')'; if ( ($qry = mysql_query($sql,$this->_db)) ) { $id = mysql_insert_id($this->_db); $this->_idportable= $id; $returnValue = $id; } else { $this->error(mysql_error($this->_db).' : '.$sql); } return $returnValue; } /** * Modifie un element d'apres son $id * @pre : la table existe avec les bons champs * @pre : tous les parametres ont été correctement configurés * @pre : l'enregistrement avec le numero $id existe * @post : l'enregistrement avec le numero $id est modifié * @return true si aucune erreur */ function updateItem($id) { $returnValue = false; if ( is_numeric($id) && $id != 0 ) { $sql = 'UPDATE inv_portable SET idtxt=\''.mysql_real_escape_string($this->_idtxt, $this->db).'\' WHERE idportable='.$id; if ( mysql_query($sql,$this->_db) === FALSE) { $this->error(mysql_error($this->_db).' : ' .$sql); } else { $returnValue=true; $this->_idportable = $id; } } return $returnValue; } /** * Affichage de la liste en XHTML */ function toXHTML() { $retour = ''; $sql = 'SELECT idportable, idtxt FROM inv_portable'; if ( ($qry = mysql_query($sql, $this->_db)) ) { if ( mysql_num_rows($qry) ) { $retour .= '
Aucun élément dans la liste.
'; } } else { $this->error(mysql_error($this->_db)); } return $retour; } /** * Affichage de la liste dans un tableau XHTML */ function toXHTMLTable() { $retour = 'idportable | idtxt |
---|---|
'.$obj->idportable.' | '; $retour .= ''.htmlspecialchars(stripslashes($obj->idtxt)).' | '; $retour .= '