Connection à plusieur base de donnés
Salut à tous,
Voila j'ai un problème assez gênant et je c'est pas comment m'y prendre, je fait un site mais avec 5 BDDs sur le meme HOST,
Donc ma déjà dit :
Citation:
Tu rassemble tes tables dans une même base de données et tu fais comme tout le monde.
Donc directement NON impossible pour certaines raison non importantes
Donc voici mon script :
Code:
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
|
<?php
class Config {
protected $MySQLUser = "root"; // MySQL Username
protected $MySQLPassword = ""; // MySQL Password
protected $MySQLHost = "127.0.0.1"; // MySQL Host IP-Address or Domainname
protected $MySQLPort = "3306"; // MySQL Port option
protected $MySQLDBChar = "characters"; // MySQL Database Character
protected $MySQLDBMaNGOS = "mangos"; // MySQL Database Character
protected $MySQLDBrealmd = "realmd"; // MySQL Database Character
protected $MySQLDBScriptDev2 = "scriptdev2"; // MySQL Database Character
protected $MySQLDBPandoreWeb = "pandoreweb"; // MySQL Database Character
protected $MySQLConnection; // MySQL
public function __construct (){
return $this->MySQLConnect();
}
public function MySQLConnect (){
$this->MySQLConnection = mysql_connect($this->MySQLHost.":".$this->MySQLPort, $this->MySQLUser, $this->MySQLPassword) or die("Database Error: ".mysql_errno()." : ".mysql_error());
}
public function MySQLDBCharacters () {
$this->MySQLCharacters = mysql_select_db($this->MySQLDBChar) or die("Database Error: ".mysql_errno()." : ".mysql_error());
}
public function MySQLDBMangos () {
$this->MySQLMangos = mysql_select_db($this->MySQLDBMaNGOS) or die("Database Error: ".mysql_errno()." : ".mysql_error());
}
public function MySQLDBRealmd () {
$this->MySQLRealmd = mysql_select_db($this->MySQLDBrealmd) or die("Database Error: ".mysql_errno()." : ".mysql_error());
}
public function MySQLDBScriptDev2 () {
$this->MySQLScriptDev2 = mysql_select_db($this->MySQLDBScriptDev2) or die("Database Error: ".mysql_errno()." : ".mysql_error());
}
public function MySQLDBPandoreWeb () {
$this->MySQLPandoreWeb = mysql_select_db($this->MySQLDBPandoreWeb) or die("Database Error: ".mysql_errno()." : ".mysql_error());
}
public function MySQLClose () {
return mysql_close($this -> MySQLConnect());
}
}
$MySQL = new Config;
$MySQL -> MySQLConnect();
$MySQL -> MySQLDBCharacters();
$MySQL -> MySQLDBMangos();
$MySQL -> MySQLDBRealmd();
$MySQL -> MySQLDBScriptDev2();
$MySQL -> MySQLDBPandoreWeb();
?> |
ET :
Code:
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
<?php
class News extends Config {
public function __construct () {
Config :: MySQLDBPandoreWeb();
}
public function Pagination($table,$order) {
$this->MessagesParPage = 10;
$this->RetourTotalNews = mysql_query('SELECT COUNT(*) AS total FROM '.$table.'', $this->MySQLPandoreWeb) or die("".mysql_error()." Database Error: ".mysql_errno()."");
$this->DonnesTotalNews = mysql_fetch_assoc($this->RetourTotalNews);
$this->RetourTotal = $this->DonnesTotalNews['total'];
$this->NombreDePages = ceil($this->RetourTotal / $this->MessagesParPage);
if(isset($_GET['Pages'])) {
$this->PageActuelle = intval($_GET['Pages']);
if($this->PageActuelle > $this->NombreDePages) {
$this->PageActuelle = $this->NombreDePages;
}
}
else {
$this->PageActuelle = 1;
}
$this->PremiereEntree = ($this->PageActuelle - 1) * $this->MessagesParPage;
$this->RetourFinal = mysql_query('SELECT * FROM '.$table.' ORDER BY '.$order.' DESC LIMIT '.$this->PremiereEntree.', '.$this->MessagesParPage.'') or die("Database Error: ".mysql_errno()." : ".mysql_error());
}
public function Affichage() {
News::Pagination('news','dates');
while ($this->ResultatForumPostReponse = mysql_fetch_assoc($this->RetourFinal)) {
echo ('<div id="news">
<div id="newsheader"><div id="newsheadertexte">'.$this->ResultatForumPostReponse['titre'].'</div></div>');
echo ('<div id="newsback">
<div id="newsbackheader">
</div>
<div id="newsbackbody">
<div id="texte">'.$this->ResultatForumPostReponse['message'].'
</div>
</div>
<div id="newsbackfooter">
</div>
<br />
<div id="newsbackheader">
</div>
<div id="newsbackbody">
<div id="texte">Par '.$this->ResultatForumPostReponse['auteur'].' le '.$this->ResultatForumPostReponse['dates'].'');
if ($this->ResultatForumPostReponse['maj'] == 1) {
echo ('<div id="right">Mise à jour par '.$this->ResultatForumPostReponse['auteurmaj'].' le '.$this->ResultatForumPostReponse['datesmaj'].'</div>');
}
else {
}
echo ('
</div>
</div>
<div id="newsbackfooter">
</div>
</div>
<div id="newsbas"></div>
</div>');
}
echo ('<div id="news"><div id="newsheader"><div id="newsheadertexte"><div id="centre">');
$this->PrecedanteVariable = $this->PageActuelle - 1; // numéro de la page précédente
$this->SuivanteVariable = $this->PageActuelle + 1; // numéro de la page suivante
if ($this->PageActuelle > 1) {
$this->Precedant = '<a href="?Page=Accueil&Pages='.$this->PrecedanteVariable.'">Précédante</a>';
}
else {
$this->Precedant = '';
}
echo ('<div id="left">'.$this->Precedant.'</div> Pages ');
for($this->ip = 1; $this -> ip <= $this->NombreDePages; $this->ip ++) {
if($this->ip == $this->PageActuelle) {
echo ' ['.$this->ip.']';
}
else {
echo (' <a href="?Page=Accueil&Pages='.$this->ip.'">'.$this->ip.'</a>');
}
}
echo (' sur ['.$this->NombreDePages.']');
if ($this->PageActuelle < $this->NombreDePages) {
$this->Suivant = '<a href="?Page=Accueil&Pages='.$this->SuivanteVariable.'">Suivante</a>';
}
else {
$this->Suivant = '';
}
echo ('<div id="right">'.$this->Suivant.'</div>');
echo ('</div></div></div><div id="newsbas"></div></div>');
}
}
?> |
Donc ca me renvoie
Citation:
Warning: mysql_query() expects parameter 2 to be resource, boolean given in E:\xamppnouveaux\htdocs\pandoreweb\Fonctions\News\News.class.php on line 15
Et si je fait :
Citation:
$MySQL->MySQLPandoreWeb
Il me dit que $MySQL n'existe pas alors que si !!!
Voila je suis perdu, et j’espère avoir postez dans la bonne sections ^^
Merci d'avoir lut :)