Source: lesson_08_db_ajout.php | Résultat |
<?php require ("lesson_08_db_connect.php"); $db_exec = new db_exec(); $db_exec->function_db_connect(); //$db_exec->get_connect();
// - use of: db_exec() // - this shows its use with INSERT $sql = "INSERT INTO atelierphp_exe_test_8 (`chapter_title`,`chapter_directory`,`chapter_title_2`) VALUES ('vive les vacances', 'vive les vacances', 'vive les vacances')"; if($db_exec->db_set_exec($sql)) { echo "Insersion réussie"; } else { echo "Echec lors de l'insersion"; 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; } } ?>
| Insersion réussie
|