01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
|
|
<?php
/******************************************************************************/
/* */
/* __ ____ */
/* ___ / / ___ / __/__ __ _____________ ___ */
/* / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-< */
/* / .__/_//_/ .__/___/\___/\_,_/_/ \__/\__/___/ */
/* /_/ /_/ */
/* */
/* */
/******************************************************************************/
/* */
/* Titre : Explorateur MySQL */
/* */
/* URL : http://www.phpsources.org/scripts499-PHP.htm */
/* Auteur : bemale */
/* Date édition : 18 Mars 2009 */
/* Website auteur : http://frederic.morinfj.free.fr */
/* */
/******************************************************************************/
/************************************************************
* Créé le 17/03/2009 par Bemale
* Modifiée le 19/03/2009 gestion des doublons.
*
* bdd::open attend le serveur, l'utilisteur, le mot de passe
*
**************************************************************/
$bdd = bdd::open("localhost","root","");
$bdd->connect();
$schema = (!empty($_POST["bdd"]))?$_POST["bdd"]:"";
$table = (!empty($_POST["tables"]))?$_POST["tables"]:"";
$normal = (!empty($_POST["comment"]) && $_POST["comment"]=="normal")?"checked":
"";
$doublon= (!empty($_POST["comment"]) && $_POST["comment"]=="doublon")?"checked":
"";
if (!empty($_POST["cle"])&&!empty($_POST["valeur_sup"]))
$bdd->supprime($schema,$table,$_POST["cle"],stripslashes($_POST["valeur_sup"
]));
?>
<html>
<head>
<title>
Bdd_explorer.php
</title>
<style type="text/css">
table.bordpurple
{
background-color: #C28FC3;
text-align: center;
}
th.bordpurple
{
background-color: #CC99CC;
}
td.bordpurple
{
background-color: #D6BADE;
}
body
{
background: #F9EEF9;
}
select
{
font-weight: bold;
background: #F9EEF9;
}
</style>
</head>
<body>
<form name="formulaire" action="http:<?php echo $_SERVER["PHP_SELF"]; ?>
" method="post">
<table>
<tr>
<td valign="bottom" height="50">
<?php echo $bdd->voir_bdd_select($schema);?>
</td>
<td rowspan="3">
<?php
if (empty($doublon))
echo $bdd->voir_table_tableau($schema,$table);
else
echo $bdd->voir_table_doublon($schema,$table);
?>
</td>
</tr>
<tr>
<td valign="top" height="30">
<?php
echo $bdd->voir_tables_select($schema,$table);
?>
</td>
</tr>
<tr>
<td valign="top">
<input type="radio" name="comment" value="normal" <?php echo $normal;?>
onchange="submit();"> Normal</br>
<input type="radio" name="comment" value="doublon" <?php echo $doublon;?>
onchange="submit();"> Doublon</br>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
$bdd->closedb();
class bdd
{
private $connect_id;
private $host;
private $user;
private $pass;
private $schema;
private $table;
function bdd() {
$this->connect_id = '';
$this->host = '';
$this->pass = '';
$this->user = '';
$this->schema = '';
$this->table = '';
}
static function open($host='',$user='',$pass='',$schema='')
{
$tmp = new bdd();
try
{
$tmp->Set_host($host);
$tmp->Set_user($user);
$tmp->Set_pass($pass);
$tmp->Set_schema($schema);
$tmp->connect();
}
catch (Exception $e)
{
echo $e->getMessage();
}
return $tmp;
}
function connect()
{
$this->connect_id = @mysql_connect($this->host,$this->user,$this->pass);
switch (mysql_errno())
{
case 1045 :
{
throw new Exception('Une erreur s\'est produite '.mysql_error())
;
break;
}
default :
{
break;
}
}
}
function voir_bdd()
{
$list = mysql_listdbs($this->connect_id);
while ($db = mysql_fetch_object($list))
{
foreach ($db as $cle => $valeur) {
echo '<'.$cle.'>'.$valeur.'</'.$cle.'>';
}
}
}
function voir_bdd_select($schema)
{
$list = mysql_listdbs($this->connect_id);
$tmp =
'<SELECT name="bdd"' .
' onchange="if(formulaire.tables){formulaire.tables.value=\'\'};submit();">';
$tmp .= '<OPTION value="">Choisir un schema</OPTION>';
while ($db = mysql_fetch_object($list))
{
$select = ($schema==$db->Database)?"selected":"";
$tmp .= '<option value="'.$db->Database.'" '.$select.'>'.$db->
Database.'</option>';
}
$tmp .= '</option>';
return $tmp;
}
function voir_tables_select($schema,$table)
{
$tmp = "pas de choix de schema";
if (!empty($schema))
{
$this->schema = $schema;
$list = mysql_list_tables($this->schema,$this->connect_id);
$tmp = '<SELECT name="tables" onchange="submit();">';
$tmp .= '<OPTION value="">Choisir une table</OPTION>';
while ($tables = mysql_fetch_assoc($list))
{
foreach ($tables as $valeur)
{
$temp = mysql_list_fields($this->schema,$valeur);
$select = ($valeur==$table)?"selected":"";
$tmp .= '<OPTION value="'.$valeur.'" '.$select.'>'.$valeur.
' ('.mysql_num_fields($temp).')</OPTION>';
}
}
$tmp .= '</SELECT>';
}
return $tmp;
}
function voir_table_tableau($schema='',$table='')
{
if (!empty($table) && !empty($schema))
{
$this->schema = $schema;
$this->table = $table;
$query = 'SELECT * FROM '.$this->table;
$colspan = mysql_num_fields(mysql_list_fields($this->schema,$this->
table));
mysql_select_db($this->schema,$this->connect_id);
$res = mysql_query($query,$this->connect_id);
$tmp =
'<table class="bordpurple" cellpading="1" cellspacing="1"><tr>';
$tmp .= '<th colspan="'.$colspan.'" class="bordpurple" >'.strtoupper
($this->table).'</th></tr><tr>';
while ($def = mysql_fetch_field($res))
{
$tmp .= '<th class="bordpurple">';
$tmp .= strtoupper($def->name);
$tmp .= '</br>';
$tmp .= ($def->primary_key==1)?"PK ":" ";
$tmp .= $def->type." (".$def->max_length.")";
$tmp .= '</th>';
}
$tmp .= '</tr>';
while ($ligne = mysql_fetch_assoc($res))
{
$tmp .= '<tr>';
foreach ($ligne as $valeur)
{
$tmp .= '<td class="bordpurple">';
$tmp .= htmlspecialchars(stripslashes($valeur));
$tmp .= '</td>';
}
$tmp .= '</tr>';
}
$tmp .= '</table>';
}
else
$tmp = 'Pas de table selectionnée.';
return $tmp;
}
function voir_table_doublon($schema='',$table='')
{
if (!empty($table) && !empty($schema))
{
$this->schema = $schema;
$this->table = $table;
$tab_pk = array();
$tab_champs = array();
$alias1 = substr($this->table,0,1)."1";
$alias2 = substr($this->table,0,1)."2";
$colspan = mysql_num_fields(mysql_list_fields($this->schema,$this->
table));
mysql_select_db($this->schema,$this->connect_id);
$res = mysql_query('SELECT * FROM '.$this->table,$this->connect_id);
$tmp =
'<table class="bordpurple" cellpading="1" cellspacing="1"><tr>';
$tmp .= '<th colspan="'.$colspan.'" class="bordpurple" >'.strtoupper
($this->table).'</th></tr><tr>';
while ($def = mysql_fetch_field($res))
{
//On sépare la clé des autres champs
if ($def->primary_key==1)
{
$tab_pk[]=$def->name;
}
else
$tab_champs[]=$def->name;
}
if (count($tab_pk)==1)
{
$query = 'SELECT '.$alias1.'.* FROM '.$this->table.' '.$alias1.
' JOIN '.$this->table.' '.$alias2.' ON ';
$query_part='';
foreach ($tab_champs as $champ)
{
//IFNULL pour pouvoir joindre même en cas de champ null
$query_part.=(!empty($query_part))?" AND ":"";
$query_part.="IFNULL(".$alias1.".".$champ.",0)=IFNULL(".
$alias2.".".$champ.",0) ";
}
$query .= $query_part.'GROUP BY '.$alias1.'.'.$tab_pk[0].
' HAVING count('.$alias2.'.'.$tab_pk[0].')>=2';
$tmp = $this->cree_tableau_doublon($schema,$table,$query);
}
else
$tmp = "Plus d'une ou pas de clé primaire.";
}
else
$tmp = 'Pas de table selectionnée';
return $tmp;
}
function cree_tableau_doublon($schema='',$table='',$query='')
{
if (!empty($table) && !empty($schema))
{
$this->schema = $schema;
$this->table = $table;
$cle = '';
$colspan = mysql_num_fields(mysql_list_fields($this->schema,$this->
table))+1;
mysql_select_db($this->schema,$this->connect_id);
$res = mysql_query('SELECT * FROM '.$this->table,$this->connect_id);
$tmp =
'<table class="bordpurple" cellpading="1" cellspacing="1"><tr>';
$tmp .= '<th colspan="'.$colspan.'" class="bordpurple" >'.strtoupper
($this->table).'</th></tr><tr>';
while ($def = mysql_fetch_field($res))
{
$tmp .= '<th class="bordpurple">';
$tmp .= strtoupper($def->name);
$tmp .= '</br>';
if ($def->primary_key==1)
{
$cle = $def->name;
$tmp .= "PK ";
}
else
$tmp .=" ";
$tmp .= $def->type." (".$def->max_length.")";
$tmp .= '</th>';
}
$res = mysql_query($query,$this->connect_id);
$tmp .=
'<th class="bordpurple"><input type="hidden" name="cle" value="'.$cle.
'"><input type="hidden" name="valeur_sup" value="">Suppr.</th></tr>';
while ($ligne = mysql_fetch_assoc($res))
{
$valeurcle='';
$tmp .= '<tr>';
foreach ($ligne as $key=>$valeur)
{
$valeurcle = ($key==$cle)?$valeur:$valeurcle;
$tmp .= '<td class="bordpurple">';
$tmp .= htmlspecialchars(stripslashes($valeur));
$tmp .= '</td>';
}
$tmp .= '<td class="bordpurple">';
$tmp .=
'<input type="button" name="SUP" value="OK" onclick="valeur_sup.value='.
$valeurcle.';submit();">';
$tmp .= '</td>';
$tmp .= '</tr>';
}
$tmp .= '</table>';
}
else
$tmp = 'Pas de table selectionnée.';
return $tmp;
}
//Supprime la ligne selectionnée
function supprime($schema='',$table='',$cle='',$valeur='')
{
if (!empty($schema) && !empty($table) && !empty($cle) && !empty($valeur)
)
{
$this->schema = $schema;
$this->table = $table;
mysql_select_db($this->schema,$this->connect_id);
$query = 'DELETE FROM '.$this->table." WHERE ".$cle."='".$valeur."'"
;
mysql_query($query,$this->connect_id);
}
}
function cleanText($intext) {
return utf8_encode(htmlspecialchars(stripslashes($intext)));
}
function closedb() {
mysql_close($this->connect_id);
}
/*
* Les setteurs
*/
function Set_host($host)
{
$this->host = $host;
}
function Set_user($user)
{
$this->user = $user;
}
function Set_pass($pass)
{
$this->pass = $pass;
}
function Set_schema($schema)
{
$this->schema = $schema;
}
function Set_table($table)
{
$this->table = $table;
}
}
?>
|