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
|
class Connexion {
// connect to the server
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);
}
/*
else
{
echo 'connected';
}
*/
$char = $this->connexion->set_charset("utf8");
} // end __construct
// select databse
public final function db_name($db_name)
{
$this->db_name = $db_name;
$s_db = $this->connexion->select_db($this->db_name);
/*
if($s_db)
{
echo 'db selected';
}
*/
} // end db_name
public final function toDo($method='', $fields=array(), $table_name='')
{
// method: select, create, insert, delete, update, read (CRUD)
$this->method = $method;
$this->fields = $fields;
$this->table_name = $table_name;
global $r;
$this->r = $r;
if(!is_object($r)){echo"<font color='red' size='5'>DB N EST PAS UN OBJET</font>";} else {echo 'is object';}
switch($this->method)
{
case 'SELECT':
$this->select = "$this->method $fields FROM $this->table_name";
echo $this->select;
$this->result = $r->query($this->select);
//$this->query = mysql_query($select) OR DIE (mysql_error());
break;
} // EnD switch
} // end toDo |
Partager