1 2 3 4 5 6 7 8 9 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
|
<?php
include 'connect.php';
mysqli_report(MYSQLI_REPORT_ERROR);
class Connexion {
public function __construct($db_host='', $db_user='', $db_passwd='')
{
$this->db_host = $db_host;
$this->db_user = $db_user;
$this->db_passwd = $db_passwd;
$this->connexion = $connexion;
$this->connexion = new mysqli($db_host, $db_user, $db_passwd); //HOST, USER, PASSWORD
if ($mysqli->connect_error)
{
die('Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error);
}
if (!$this->connexion->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $this->connexion->error);
} else {
printf("Current character set: %s\n<br>", $this->connexion->character_set_name());
}
}
public final function db_name($db_name) //DBNAME
{
$this->db_name = $db_name;
if(!$this->connexion->select_db($this->db_name))
{
echo 'db not select<br>';
}
}
public final function select() //$fields, $table_name
{
$this->select = $select;
$this->resultat = $resultat;
$this->smt = $smt;
$this->select = "SELECT id_sgp, sgp_name_ar FROM users_sgroups";
echo $this->select.'<br>';
$this->resultat = $this->connexion->query($this->select);
$this->smt = $this->connexion->prepare($this->select);
$this->smt->execute();
}
public final function num_rows()
{
/* determine number of rows result set */
$row_cnt = $this->smt->num_rows;
echo 'nbre: '.$row_cnt;
}
public final function display_Results()
{
$this->smt->bind_result($id_sgp, $sgp_name_ar);
$this->smt->fetch();
echo 'sgp: '.$id_sgp;
}
}
$r = new Connexion($db_host, $db_user, $db_passwd);
$r->db_name('test');
$r->select();
$r->num_rows();
$r->display_Results();
?> |
Partager