Bonjour,
Je suis pas calé du tout en PHP, mais j'ai besoin de comprendre comment une connexion se fait entre du PHP et une base MYSQL.
Je dois effectivement déplacer une application, mais son concepteur n 'est plus de ce monde, et je n'ai aucune info concernant les pré-requis ou autre directives pour son installation.
Pour l'instant, j'ai déplacé le contenu du dossier /var/www/appli sur le nouveau serveur, et dupliqué la base Myql (mysqldump, puis mysql < save.sql.. bref, méthode classique).
J'ai mis le même mot de passe root dur les deux serveurs (j'ai repris celui de l'ancien serveur Mysql, qui était connu et je lai mis sur le nouveau serveur, soit même config à ce niveau-là : connexion en root, puis mot de passe identique sur les deux serveurs).
Mais voilà, apparemment ça ne fonctionne pas ! Il me dit "impossible de se connecter au serveur".
Je me suis donc plongé dans le source et j'ai essayé de trouvé ce qui n'allait pas, mais je me heurte à php, que je connais trop mal !
Donc, finalement, la question se résume à "comment le code php de cette appli ouvre la base MySql" (L'appli fonctionne avec ce même source sur un serveur avec Fedora 4 (PHP5), le nouveau serveur est sous Ubuntu 8.04 (PHP5.2) )
Voici quelques extraits du code : (j'ai renommé dans le code tout ce qui pourrait être dangereux pour la société si une personne mal intentionnée tombe sur ce code !)
(et Albert Dupont n'est absolument pas la personne qui avait développé ce code)
A propos, les Logs ne sont pas très bavards, mais s'il vous les faut, je peux le faire en mode le plus explicite possible...
Tout d'abord , le fichier login.php, sur lequel sont envoyés le nom "chpUser" et le mot de passe "chpUserPwd" en _POST depuis le formulaire de saisie :
Le fichier dbConnect.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 <?php /* appli/php/login */ session_start(); include_once ("../inc/php/dbConnect.php"); include_once ("../inc/php/class/appli.php"); define('COMMENTAIRE', '#'); define('ESPACE', ' '); define('DATE_DEB', 1); define('DATE_FIN', 2); $userIdent = new User("identificateur", "cestqui","identificateur2"); //if(!$cnx = getappliCnx($userIdent)){ if(!$cnx = $userIdent->getConnexion()){ include("../inc/errSrvSql.html"); exit(); } $userappli= new User(strtoupper(stripslashes($_POST['chpUser'])), $_POST['chpUserPwd']); $qryIdent = "SELECT userId, passWd, userId2 FROM appli.users WHERE desactive IS NULL AND userId = '" . $userappli->getUserId() . "' AND passWd = '" . $userappli->getPassWord() . "'"; if(!$result = $cnx->query($qryIdent)){ printf("Erreur requête SQL : <br>%s<br>", $cnx->error); exit(); } if (!$result->num_rows){ $cnx->close(); echo '<div class="err"><h1> </h1><h1>L\'identification n\'a pu être établie</h1> <h1> </h1><h1> </h1><p class="msg"><b>VEUILLEZ VERIFIER VOTRE IDENTIFIANT et (ou) MOT DE PASSE</b></p> <h1> </h1><h1> </h1><table with="99%" align="center" border="0"> <tr><td><input type="button" value="Continuer" onclick="window.history.back();"></td></tr> </table>'; } else{ /*********************************************************** ** ** NE SUPPRIMER LES LIGNES SUIVANTES SOUS AUCUN PRÉTEXTE ** ************************************************************/ // Ce test est obligatoire, il permet de savoir si l'utilisateur MySQL pour l'appli est bien créé // et de crypter en interne (sans passer par le web, donc non détectable) le mot de passe // pour éviter toute tentative de hack. // C'est cet utilisateur qui sera utilisé durant toute la session $cnx->close(); $userCnx = new User($userappli->getUserId(), md5($userappli->getPassWord())); if(!$cnx = $userCnx->getConnexion()){ echo '<scrpit language="JavaScript"> alert("La connexion à la base a échouée\nIMPOSSIBLE DE CONTINUER !!!"); window.history.back(); </script>'; } // Ajout du type d'utilisateur $qryUserType = "SELECT userType FROM users WHERE userId='" . $userappli->getUserId() . "'"; if(!$result = $cnx->query($qryUserType)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qryUserType; exit(); } $userappli->setUserType($result->fetch_object()->userType); // Mise en session de l'utilisateur $_SESSION['userCnx'] = serialize($userCnx); // Si type utilisateur == ORGAAS on le redirige vers le choix de l'appli à consulter if ( $userappli->getUserType() ){ header("Location: ../ORGAAs/choixappli.php"); } $appli = new appli($userappli->getUserId()); $_SESSION['objappli'] = serialize($appli); $qryORGAAs = "SELECT ORGAAs FROM appli WHERE codeappli = '" . $userappli->getUserId2() . "' AND ORGAAs = 1"; if(!$result = $cnx->query($qryORGAAs)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qryORGAAs; exit(); } $nbrappli = $cnx->affected_rows; /************************ ** AFFICHAGE DES MESSAGES *************************/ $fileMsgGral = "../msg/motd/MessageToutesappli.txt"; $fileMsgappli = "../msg/" . $appli->getCode() . "msg.txt"; $fileMsgORGAAS = "../msg/ORGAASmsg.txt"; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/html4/loose.ddt"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="author" content="Albert Dupont"> <title>Identification en cours...</title> <link lang="fr" media="all" rel="stylesheet" type="text/css" href="../inc/css/first.css" /> </head> <body> <table align="center" border="0" cellpadding="-1" cellspacing="-1"> <tr><td> <table align="center" border="0" cellpadding="-1" cellspacing="-1"> <tr><td> <?php if(file_exists($fileMsgGral)){ if(!($fpr = fopen($fileMsgGral, 'r'))){ echo '<h2>OUVERTURE DU FICHIER MESSAGE GÉNÉRAL IMPOSSIBLE</h2>'; exit(); } $msgGral = ''; while(!feof($fpr)){ $ligne = fgets($fpr, 4096); $carComment = substr($ligne, 0, 1); if($carComment != COMMENTAIRE){ if($carComment == ESPACE){ $ligne = substr($ligne, 1, strlen($ligne)-1); } $msgGral .= $ligne; } } fclose($fpr); echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="12" >', $msgGral, '</textarea>'; } else{ echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="12" ></textarea>'; } echo '</td></tr> </table> </td></tr> <tr><td> <table align="center" border="0" cellpadding="-1" cellspacing="-1"> <tr><td>'; if(file_exists($fileMsgORGAAS) && ($nbrappli)){ if(!($contenu = file($fileMsgORGAAS))){ echo '<h3>Problème d\'ouverture du fichier [ ', $fileMsgORGAAS, ' ]'; exit(); } // Ficher en cours de validité $maintenant = date("YmdHi") * 1; //$maintenant *= 1; $dateDeb = $contenu[DATE_DEB] * 1; $dateFin = $contenu[DATE_FIN] * 1; if( ($maintenant >= $dateDeb) && ($maintenant <= $dateFin)){ // Suppression du message d'avertissement, et des valeurs paramètres (Dates deb et fin) array_splice($contenu, 0, 3); echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="8" >', implode("", $contenu), '</textarea>'; } else{ if (file_exists($fileMsgappli)) { if (!($contenu = file($fileMsgappli))) { echo '<h3>Problème d\'ouverture du fichier [ ', $fileMsgappli, ' ]'; exit(); } // Ficher en cours de validité $maintenant = date("YmdHi") * 1; //$maintenant *= 1; $dateDeb = $contenu[DATE_DEB] * 1; $dateFin = $contenu[DATE_FIN] * 1; if( ($maintenant >= $dateDeb) && ($maintenant <= $dateFin)){ // Suppression du message d'avertissement, et des valeurs paramètres (Dates deb et fin) array_splice($contenu, 0, 3); echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="8" >', implode("", $contenu), '</textarea>'; } else{ echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="8" ></textarea>'; } } else { echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="8" ></textarea>'; } } } else{ if (file_exists($fileMsgappli)) { if (!($contenu = file($fileMsgappli))) { echo '<h3>Problème d\'ouverture du fichier [ ', $fileMsgappli, ' ]'; exit(); } // Ficher en cours de validité $maintenant = date("YmdHi") * 1; //$maintenant *= 1; $dateDeb = $contenu[DATE_DEB] * 1; $dateFin = $contenu[DATE_FIN] * 1; if( ($maintenant >= $dateDeb) && ($maintenant <= $dateFin)){ // Suppression du message d'avertissement, et des valeurs paramètres (Dates deb et fin) array_splice($contenu, 0, 3); echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="8" >', implode("", $contenu), '</textarea>'; } else{ echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="8" ></textarea>'; } } else { echo '<textarea class="txtAreaappli" name="txtMessage" cols="80" rows="8" ></textarea>'; } } echo '</td></tr> </table> </td></tr> </table>'; /********************* ** FIN DES MESSAGES *********************/ echo '<p class="libbc" align="center">Pour continuer, cliquez <a href="menu.php"><b>ICI</b></a></p>'; } ?> </body> </html>
le fichier appli.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 <?php include_once("class/User.php"); /* ** Fonction de connexion a la base de donnees ** GARDEE POUR COMPATIBILITE VERSIONS PRECEDENTES ** ------------------------------------------------- ** il faut utiliser celle fournie dans la class User ** ------------------------------------------------- */ function getappliCnx($userObj){ $host = "localhost"; $dbName = "appli"; // Construction de l'objet (Connexion � la base) if(!$cnx = new mysqli($host, $userObj->getUserId(), $userObj->getPassWord(), $dbName)){ return null; } if (mysqli_connect_errno()) return null; return $cnx; } ?>
Le fichier User.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320 <?php //private $_euro = 0; // Non utilise //private $_dteSaisiePrix; //private $_dteValPrix; //private $_dteToUcan; // date de passage //public function getEuro(){return $this->_euro;} //public function getDteSaisiePrix(){return $this->_dteSaisiePrix;} //public function getDteValidPrix(){return $this->_dteValPrix;} //public function getDteToORGAAs(){return $this->_dteToUcan;} //public function setEuro($euro){$this->_euro = $euro;} include_once("MyDate.php"); class appli{ private $_code = null; private $_nom = null; private $_ligAdr1 = null; private $_ligAdr2 = null; private $_ligAdr3 = null; private $_ligAdr4 = null; private $_email = null; private $_ORGAAs = 0; // 0 = non ; 1 = oui private $_miniere = 0; private $_teteEtiq = 'CO'; // Tete d'etiquette private $_contact1 = null; private $_contact2 = null; private $_contact3 = null; private $_contact4 = null; private $_tel1 = null; private $_tel2 = null; private $_tel3 = null; private $_tel4 = null; private $_codeCmde = null; private $_dteToWeb = null; // date de passage a Internet private $_toEloq = null; private $_new = true; // Constructeur public function __construct($codeappli = null){ global $cnx; // Controle que le code n'est pas null et le departement est numerique if(!$codeappli){ //echo 'Impossible de construre l\'objet appli, le code est null ou invalide !!!<br>'; echo "<script language=\"JavaScript\">\n"; echo 'alert("Impossible de construre l\'objet appli, le code \'' . $codeappli . '\' est null ou invalide !!!");'; echo "</script>\n"; return null; } // Controle qu'une connexion a la DB valide existe if(!$cnx){ echo 'echo Impossible de construre l\'objet la connexion au serveur es nulle !!!<br>'; echo 'Arrêt du programme obligatoire !!!<br>'; exit(); } $this->_code = $codeappli; // Affectation du code appli // construction de la requete pour recherche dans DB $qryGetappli = "select codeappli, nom, ligAdr1, ligAdr2, ligAdr3, ligAdr4, email, contact1, contact2, contact3, contact4, "; $qryGetappli .= "tel1, tel2, tel3, tel4, ORGAAs, miniere, teteEtiq, dteToWeb, toEloq from appli.appli"; $qryGetappli .= " where codeappli = '" . $codeappli ."';"; //echo $qryGetappli .'<br>'; if(!$result = $cnx->query($qryGetappli)){ // err sql echo 'SQL ERR on SELECT appli :<br>', $cnx->error; exit(); } $nbrapplis = $cnx->affected_rows; $this->_codeCmde = substr($this->_code, 0, 2) . 'C' . substr($this->_code, 2, 2); if (!$nbrapplis) {// Nouvelle appli $this->_new = true; return; } // appli existe $this->_new = false; $rang = $result->fetch_object(); $this->_nom = $rang->nom; $this->_ligAdr1 = $rang->ligAdr1; $this->_ligAdr2 = $rang->ligAdr2; $this->_ligAdr3 = $rang->ligAdr3; $this->_ligAdr4 = $rang->ligAdr4; $this->_email = $rang->email; $this->_contact1 = $rang->contact1; $this->_contact2 = $rang->contact2; $this->_contact3 = $rang->contact3; $this->_contact4 = $rang->contact4; $this->_tel1 = $rang->tel1; $this->_tel2 = $rang->tel2; $this->_tel3 = $rang->tel3; $this->_tel4 = $rang->tel4; $this->_ORGAAs = $rang->ORGAAs; if(empty($this->_ORGAAs)) $this->_ORGAAs = 0; $this->_miniere = $rang->miniere; if(empty($this->_miniere)) $this->_miniere = 0; $this->_teteEtiq = $rang->teteEtiq; $this->_dteToWeb = $rang->dteToWeb; $this->_toEloq = $rang->toEloq; // Affectation du codeCommande } // // Fonctions GET // public function getDep(){return substr($this->_code,0,2);} public function getCodeCmde(){return $this->_codeCmde;} public function getCode(){ $code=$this->_code; if ($code=="3302" or $code=="3301C") $code="3301"; return $code;} // public function getCode(){return $this->_code;} public function getNom(){return $this->_nom;} public function getLigAdr1(){return $this->_ligAdr1;} public function getLigAdr2(){return $this->_ligAdr2;} public function getLigAdr3(){return $this->_ligAdr3;} public function getLigAdr4(){return $this->_ligAdr4;} public function getContact1(){return $this->_contact1;} public function getContact2(){return $this->_contact2;} public function getContact3(){return $this->_contact3;} public function getContact4(){return $this->_contact4;} public function getTel1(){return $this->_tel1;} public function getTel2(){return $this->_tel2;} public function getTel3(){return $this->_tel3;} public function getTel4(){return $this->_tel4;} public function getEmail(){return $this->_email;} public function isORGAAS(){if ((int)$this->_ORGAAs == 1) return true; return false;} public function isMiniere(){if ((int)$this->_miniere == 1) return true; return false;} public function getTeteEtiq(){return $this->_teteEtiq;} public function getDteToWeb(){return $this->_dteToWeb;} public function getDteSend(){ if ($this->sended()) return new MyDate($this->_toEloq); return null; } // //Fonctions SET // public function setNom($nom){$this->_nom = addslashes($nom);} public function setLigAdr1($ligAdr1 = ''){$this->_ligAdr1 = addslashes($ligAdr1);} public function setLigAdr2($ligAdr2 = ''){$this->_ligAdr2 = addslashes($ligAdr2);} public function setLigAdr3($ligAdr3 = ''){$this->_ligAdr3 = addslashes($ligAdr3);} public function setLigAdr4($ligAdr4 = ''){$this->_ligAdr4 = addslashes($ligAdr4);} // Un controle sur la validite de l'email devra etre mis en place (Faute de temps) public function setEmail($email = ''){$this->_email = addslashes($email);} public function setContact1($contact){$this->_contact1 = addslashes($contact);} public function setContact2($contact){$this->_contact2 = addslashes($contact);} public function setContact3($contact){$this->_contact3 = addslashes($contact);} public function setContact4($contact){$this->_contact4 = addslashes($contact);} public function setTel1($tel){$this->_tel1 = addslashes($tel);} public function setTel2($tel){$this->_tel2 = addslashes($tel);} public function setTel3($tel){$this->_tel3 = addslashes($tel);} public function setTel4($tel){$this->_tel4 = addslashes($tel);} public function setInserted(){$this->_new = false;} public function setORGAAs($ORGAAs = 0){ if ($ORGAAs != true && $ORGAAs != false && $ORGAAs !=0 && $ORGAAs != 1){ echo 'Valeur d\ORGAAS invalide, ni true ni false<br>false assume !!!<br>'; $ORGAAs = 0; // false } $this->_ORGAAs = $ORGAAs; } public function setMiniere($miniere = 0){ if ($miniere != true && $miniere != false && $miniere !=0 && $miniere != 1){ echo 'Valeur d\ORGAAS invalide, ni true ni false<br>false assume !!!<br>'; $miniere = 0; // false } $this->_miniere = $miniere; } public function setTeteEtiq($etiq = null){ $etiq = strtoupper($etiq); if($etiq != 'CO' && $etiq != 'CP'){ echo 'Valeur de tete d\'etiquette invalide, CO assume !!!<br>'; $this->_teteEtiq = 'CO'; } else $this->_teteEtiq = $etiq; } public function setDteToWeb($dteToWeb = null){ if(!$dteToWeb){ echo 'La date de passage au WEB ne peut etre nulle !!!, <br>Date du jour assumee !!!<br>'; $dteToWeb = time(); } $this->_dteToWeb = new MyDate($dteToWeb); } // //Fonctions UTILITAIRES // public function getFullAdr(){// Adresse complete $fullAdr = null; if($this->_ligAdr1 && $this->_ligAdr1 != '') $fullAdr .= $this->_ligAdr1 . "\n"; if($this->_ligAdr2 && $this->_ligAdr2 != '') $fullAdr .= $this->_ligAdr2 . "\n"; if($this->_ligAdr3 && $this->_ligAdr3 != '') $fullAdr .= $this->_ligAdr3 . "\n"; if($this->_ligAdr4 && $this->_ligAdr4 != '') $fullAdr .= $this->_ligAdr4 . "\n"; return $fullAdr; } public function wasSended(){ if ($this->_toEloq) return true; return false; } public function isNew(){ return $this->_new; } public function toString(){ $stringappli = 'Code ' . $this->_code . "\n" . $this->_nom . "\n"; $stringappli .= $this->getFullAdr() . "\n"; return $stringappli; } public function toNavigator(){ echo str_replace("\n", "<br>", $this->toString()); } // //Fonctions Base de donnees // private function prepareSqlInsUpd($action){ $act = strtoupper($action); if($act != 'UPD' && $act != 'INS'){ echo 'Préparation de la requête impossible, code action <b>(', $action, ')</b> inconnu !!!<br>'; exit(); } $qry = null; if($act == 'UPD') $qry .= "nom = "; $qry .= "'" . $this->_nom . "', "; if($act == 'UPD') $qry .= "ligAdr1 = "; $qry .= "'" . $this->_ligAdr1 . "', "; if($act == 'UPD') $qry .= "ligAdr2 = "; $qry .= "'" . $this->_ligAdr2 . "', "; if($act == 'UPD') $qry .= "ligAdr3 = "; $qry .= "'" . $this->_ligAdr3 . "', "; if($act == 'UPD') $qry .= "ligAdr4 = "; $qry .= "'" . $this->_ligAdr4 . "', "; if($act == 'UPD') $qry .= "email = "; $qry .= "'" . $this->_email . "', "; if($act == 'UPD') $qry .= "contact1 = "; $qry .= "'" . $this->_contact1 . "', "; if($act == 'UPD') $qry .= "contact2 = "; $qry .= "'" . $this->_contact2 . "', "; if($act == 'UPD') $qry .= "contact3 = "; $qry .= "'" . $this->_contact3 . "', "; if($act == 'UPD') $qry .= "contact4 = "; $qry .= "'" . $this->_contact4 . "', "; if($act == 'UPD') $qry .= "tel1 = "; $qry .= "'" . $this->_tel1 . "', "; if($act == 'UPD') $qry .= "tel2 = "; $qry .= "'" . $this->_tel2 . "', "; if($act == 'UPD') $qry .= "tel3 = "; $qry .= "'" . $this->_tel3 . "', "; if($act == 'UPD') $qry .= "tel4 = "; $qry .= "'" . $this->_tel4 . "', "; if($act == 'UPD') $qry .= "ORGAAs = "; $qry .= "'" . $this->_ORGAAs . "', "; if($act == 'UPD') $qry .= "miniere = "; $qry .= "'" . $this->_miniere . "', "; if($act == 'UPD'){ $qry .= "teteEtiq = "; $qry .= "'" . $this->_teteEtiq . "'"; } else $qry .= "'" . $this->_teteEtiq . "', CURRENT_TIMESTAMP()"; return $qry; } public function getQryInsert(){ if($this->_new == false){ echo 'Insertion de l'appli <b>', $this->_code, '</b> IMPOSSIBLE, l'appli existe !!!<br>'; return false; } if(!$this->_nom || $this->_nom == ''){ echo 'Insertion de l'appli <b>', $this->_code, '</b> IMPOSSIBLE, le nom est obligatoire !!!<br>'; return false; } $qryInsert = "insert into appli.appli (codeappli, nom, ligAdr1, ligAdr2, ligAdr3, ligAdr4, email, contact1, contact2, contact3, contact4, "; $qryInsert .= "tel1, tel2, tel3, tel4, ORGAAs, miniere, teteEtiq, dteToWeb)"; $qryInsert .= " values ('" . $this->_code . "', " . $this->prepareSqlInsUpd('ins'). ");"; return $qryInsert; } public function getQryUpdate(){ if($this->_new){ echo 'La mise à jour (UPDATE) de l'appli <b>', $this->_code, '</b> IMPOSSIBLE, l'appli n\'existe pas !!!<br>'; return false; } $qryUpd = "update appli.appli set " . $this->prepareSqlInsUpd('upd'); $qryUpd .= ", toEloq = null where codeappli = '" . $this->_code . "'"; return $qryUpd; } public function dbDelete($cnx){ //$qryDel = "delete from appli.appli where codeappli = '" . $this->_code . "';"; } // //Fonctions de TRANSFERT // public function sendToFile(){ if ($this->_toEloq){ echo 'L'appli ', $this->_code, ' à déjà été toEloq le ' . date("d/m/Y a H:i:s", new MyDate($toEloq)) . '<br>'; return null; } $homeTrans = $_SERVER['DOCUMENT_ROOT']; $homeTrans .= "/../transferts/webToEloq/appli"; /* $fp = fopen("$homeTrans/new_appli.txt", echo $homeTrans; */ } } ?>
Voilà, je suis à l'affut de tout ce qui peut m'aider à faire tourne de satané soft ! Si vous avez la moindre idée ou que vous avez besoin de plus d'infos, n'hésitez-pas, toute aide ou observation sera la bienvenue !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
143
144 <?php /* appli/inc/php/class/User */ class User { private $_uid; private $_pwd; private $_type; private $_uid2; private $_new; public $error = null; private $_host = 'localhost'; private $_db = 'appli'; public function __construct($userId, $userPass, $userId2 , $dataBase = null, $host = null) { $this->_uid = $userId; $this->_pwd = $userPass; $this->_uid2 = $userId2; if(!empty($dataBase)){ $this->_db = $dataBase; } if(!empty($host)){ $this->_host = $host; } } public function getUserId(){return $this->_uid;} public function getUserId2(){return $this->_uid2;} public function getPassWord(){return $this->_pwd;} public function getUserType(){return $this->_type;} public function getDep(){return substr($this->_uid, 0, 2);} public function setUserId($userId){$this->_uid = $userId;} public function setUserId2($userId2){$this->_uid2 = $userId2;} public function setPassWord($userPass){ $this->_pwd = $userPass;} public function setUserType($userType){$this->_type = $userType;} //---------------------------- // Obtenir une connexion a la base //---------------------------- public function getConnexion(){ $connexion = @new mysqli($this->_host, $this->_uid, $this->_pwd, $this->_db); $error = mysqli_connect_errno(); if (!$error){ $this->_new = false; return $connexion; } if ( $error == 2002){ $this->error = mysqli_connect_errno(); return false; } } //---------------------------- // Creation d'un utilisateur WEB (Base appli) //---------------------------- public function createWebUser(){ global $cnx; if(empty($cnx)){ $cnx = $this->getConnexion(); } $qryAddUserWeb = "insert into appli.users (userId, passWd, userId2) values ('" . $this->_uid . "', '". $this->_pwd . "', '" . $this->_uid2 . "');"; if(!$repQryAddUserWeb = $cnx->query($qryAddUserWeb)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qryAddUserWeb; exit(); } } //---------------------------- // Creation d'un utilisateur SQL //---------------------------- public function createSqlUser(){ global $cnx; if(empty($cnx)){ $cnx = $this->getConnexion(); } $qryCreatSqlUser = "grant usage, select, insert, update, delete on appli.* to '" . $this->_uid . "'"; $qryCreatSqlUser .= "@localhost identified by '" . md5($this->_pwd) . "';"; if(!$cnx->query($qryCreatSqlUser)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qryCreatSqlUser; exit(); } // Forcer MySql e recharger les privileges $qryForcePrivs = "flush privileges;"; $cnx->query($qryForcePrivs); } //---------------------------- // Suppression utilisateur SQL //---------------------------- public function dropSqlUser(){ global $cnx; if(empty($cnx)){ $cnx = $this->getConnexion(); } $qryUserSql = "select user.user from mysql.user where user.user = '" . $this->_uid . "' and user.host ='localhost';"; if(!$repQryUserSql = $cnx->query($qryUserSql)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qryUserSql; exit(); } if($cnx->affected_rows){ // L'utilisateur existe // Suppression des droits $qrySupSqlUser = "revoke all privileges on appli.* from '" . $this->_uid . "'@localhost;"; if(!$result = $cnx->query($qrySupSqlUser)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qrySupSqlUser; exit(); } // Suppression de l'utilisateur $qryDropUser = "drop user '" . $this->_uid . "'@localhost;"; if(!$result = $cnx->query($qryDropUser)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qryDropUser; exit(); } // Forcer MySql a recharger les privileges $qryForcePrivs = "flush privileges;"; $cnx->query($qryForcePrivs); } } //---------------------------- // Reactivation de l'utilisateur Web //---------------------------- public function reactiveWebUser(){ global $cnx; if(empty($cnx)){ $cnx = $this->getConnexion(); } $qryReact = "UPDATE appli.users SET passWd='" . $this->_pwd . "', userId2='" . $this->_uid2 . "', desactive = null WHERE userId='" . $this->_uid . "';"; if(!$result = $cnx->query($qryReact)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qryReact; exit(); } } //---------------------------- // Desactivation de l'utilisateur WEB //---------------------------- public function desactiveWebUser(){ global $cnx; if(empty($cnx)){ $cnx = $this->getConnexion(); } $qryDesactive = "UPDATE users SET desactive = CURRENT_TIMESTAMP WHERE userId='" . $this->_uid . "';"; if(!$result = $cnx->query($qryDesactive)){ echo 'ERR_SQL : ', $cnx->errno, '<br />', $cnx->error, '<br />', $qryDesactive; exit(); } } public function isNew(){ } } ?>
Merci d'avance à ceux qui voudrons bien me rendre service !
Partager