importKdissert2MySQL.php

<?php
$titrePage="importKdissert2MySQL.php create MySQL tables from a kdissert (kdi) file";
$css="http://www.akademia.ch/standard.css";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0.1//EN">
<html>
<head>
  <title><? echo $titrePage ?></title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="GENERATOR" content="Quanta Plus">
<link rel="stylesheet" type="text/css" href="<? echo $css ?>">
</head>
<body>
<h1><? echo $titrePage ?></h1>

<?
/*
[[importKdissert2MySQL.php]] create MySQL tables from a kdissert (kdi) file
 Required:  kdissert, php, mysql

Author:
 Fred Radeff, radeff@akademia.ch, www.akademia.ch
 History
 2007-12-22 07:53:47   : FR, created
 2008/04/01 11:22 modified
 No Copyright, steal this!
*/

$txt=$_POST['txt'];
$table=$_POST['table'];
$kdi=$_POST['kdi'];
$id=$_POST['id'];
?>


Ouvrir dans un éditeur de texte simple le fichier texte généré par kdi, puis:<br><br>
<?
if(strlen($txt)<1) { //formulaire initial à remplir
	echo '
	<FORM method="POST">
	Nom de la table MySQL <INPUT type="text" name="table"><br>
	Mettre ici un champ par ligne <br><textarea rows="10" cols="80" name="txt"></textarea><br>
	id auto_increment_file? oui <INPUT type="radio" name="id" value="1" checked>
	 non <INPUT type="radio" name="id" value="0"><br>

	<!--kdi file<INPUT type="radio" name="kdi" value="1" checked>
	asci file (single table)<INPUT type="radio" name="kdi" value="0">-->
	<INPUT type="submit" value="Créer tables">
	</FORM>
	<?
	';
} else { //formulaire initial complété

  $pieces = explode(chr(10), $txt); // on découpe les champs
$txtLV="";
for($i=0;$i<count($pieces);$i++){
$txtL=trim($pieces[$i]);

if($txtL!="") { // affiche pas si ligne vide
$txtLV.= "  `" .$txtL ."` text NOT NULL,";
$txtLV.= "\n";
}
}
$txtLV=ereg_replace(".$","",$txtLV);
$txtLV=ereg_replace(",$","",$txtLV);

echo "<b>COPIER-COLLER DANS PHPMyAdmin ou en ligne de commande la commande suivante:</b>
<pre>
<font color=\"red\">
CREATE TABLE IF NOT EXISTS `" .$table ."` (";
echo "\n";
echo $txtLV;
echo "\n";
	echo ") ENGINE=MyISAM DEFAULT CHARSET=utf8;";
if($id==1) {
echo "\n";
echo "ALTER TABLE `$table` ADD `id` INT( 12 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ;"; //on cree l'index
}
?>
</font>
</pre>
<p>Pratiquer de même pour toutes les tables générées par kdissert, puis utiliser phpCodeGenie pour générer les scripts php, enfin adapter les tables relationnelles et le tour est joué. Gain de temps: au moins 80%!</p>
<?
}
?>

</body>
</html>
 
info/importkdissert2mysql.txt · Dernière modification: 2008/11/19 13:54 (modification externe)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki