Hi,
I got a problem with class.
I've created 3 classes:
* identifiantsClass.php
* connectInfosClass.php
* sqlClass.php
In my third class, i always have the message: "error to connect" even if my database's name is good.
Please help me...
identifiantsClass.php
class Identifiants{
protected $serveur=null; protected $host=null; protected $mdp=null; protected $bdd=null; public function __construct(){ $this->serveur=$serveur; $this->host=$host; $this->mdp=$mdp; $this->bdd=$bdd; } public function identifiantsConnexion(){ $this->serveur="nomServeur"; $this->host='nomHote'; $this->mdp='motdepasse'; $this->bdd='bdd'; }
}
connectInfosClass.php
class Connect extends Identifiants{
protected $connection=null; protected $result=null; public function __construct(){ $this->identifiantsConnexion(); } public function connexion(){ $this->connection=mysql_connect($this->serveur,$this->host,$this->mdp); if(!$this->connection){die;} $dataBase_connect = mysql_select_db($this->bdd,$this->connection); mysql_query("SET NAMES UTF8"); if(!$dataBase_connect){$result=false;}else{$result=true;} return $result; }
}
sqlClass.php
class reqSql extends Connect{
public function __construct(){ $result=$this->connexion(); if($result==false){ echo("Error to connect to the database"); exit; } } // Here it will be my sql requests
}
I do my test in a file :
<?php
include_once('identifiantsClass.php');
include_once('connectInfosClass.php');
include_once('sqlClass.php');
$testSql=new reqSql();
?>