Source: lesson_08_db_efface.php | Résultat |
<font color=red>Effacement de tous les enregistrements de la table, s'il y en a</font><p> <?php require ("lesson_08_db_connect.php"); $db_exec = new db_exec(); $db_exec->function_db_connect(); //$db_exec->get_connect(); // - this shows its use with DELETE $sql = "DELETE FROM atelierphp_exe_test_8 "; if($db_exec->db_set_exec($sql)) { echo "Effacement réussi"; } else { echo "Echec de l'effacement"; echo $db_exec->db_get_error().""; } ?>
Fichier : lesson_08_db_connect.inc
<?php class db_connect { function function_db_connect() { require ("../commons/connect_to_db_no_die.php"); $this->host = $host; $this->user = $user; $this->pass = $pass; $this->database = "atelierpl"; } function get_connect() { mysql_connect($this->host, $this->user, $this->pass); mysql_select_db("atelierpl"); } } //------------------------------------------------ class db_select extends db_connect { var $count; var $row; function function_db_select($count=0, $row="") { $this->count = $count; $this->row = $row; } function db_set_select($sql, $num) { $qry = mysql_query($sql); $this->count = mysql_num_rows($qry); $i=0; while($out = mysql_fetch_array($qry)) { for($j=0; $j<$num; $j++ ) { $this->row[$i][$j] = $out[$j]; } $i++ ; } } function db_get_select() { return $this->row; } function db_get_count() { return $this->count; } } //--------------------------------------------------- class db_exec extends db_connect { var $sql = ""; var $err = ""; function db_set_exec($sql) { if(!mysql_query($sql)) { $this->err = mysql_error(); return false; } else { return true; } } function db_get_error(){ return $this->err; } } ?>
| Effacement de tous les enregistrements de la table, s'il y en a
Effacement réussi
|