示例#1
0
		<h2>Listing</h2>
		<?php 
$table = "users";
?>
		<h4>Table "<?php 
echo $table;
?>
"</h4>
		<pre><?php 
try {
    $l = new Listing();
    $liste = $l->getList($table);
    $liste = $l->reindexList('id');
    //			Listing::array_reindex_by($liste, 'ref');
    print_r($liste);
    var_dump(Infos::colExists($table, 'name'));
} catch (Exception $e) {
    echo '<span class="red"><b>' . $e->getMessage() . '</b></span><br />';
    echo $e->getTraceAsString();
}
?>
</pre>
	</section>
	<section style="max-width: 50%;">
		<h2>Infos</h2>
		<h4>Table "users", action : update entry</h4>
		<pre><?php 
try {
    //			$i = new Infos("users");
    //			$i->loadInfos('id', 6);
    //			$newInfos = Array("name"=>"Alex", "pseudo"=>"AKtsuki", "age"=>29 );
 /**
  * Ajoute une colonne dans une table de la base de données
  * @param STRING $table Le nom de la table
  * @param STRING $colName Le nom de la nouvelle colonne
  * @param STRING $colType Le type de colonne à créer (default "VARCHAR(64)")
  * @param STRING $defaultVal La valeur par défaut pour la colonne (optionnel, et inutile pour le type "TEXT")
  * @return BOOLEAN TRUE si succès, FALSE si erreur.
  */
 public static function addNewCol($table = '', $colName = '', $colType = 'VARCHAR(64)', $defaultVal = "")
 {
     if ($table == '') {
         throw new Exception("Infos::addNewCol() : Missing table name");
     }
     if ($colName == '') {
         throw new Exception("Infos::addNewCol() : Missing column name");
     }
     if (Infos::colExists($table, $colName)) {
         throw new Exception("Infos::addNewCol() : This column already exists");
     }
     $pdoTmp = Listing::newPDO();
     $pdoDriver = $pdoTmp->getAttribute(PDO::ATTR_DRIVER_NAME);
     $extraReq = "";
     if (preg_match('/CHAR|TEXT/i', $colType) && $pdoDriver !== 'sqlite') {
         $extraReq = "CHARACTER SET utf8 COLLATE utf8_general_ci ";
     }
     $extraReq .= "NOT NULL";
     if (!preg_match('/TEXT/i', $colType)) {
         $extraReq .= " DEFAULT '{$defaultVal}'";
     }
     $sqlAlter = "ALTER TABLE `{$table}` ADD `{$colName}` {$colType} {$extraReq}";
     $a = $pdoTmp->prepare($sqlAlter);
     return $a->execute();
 }