Explorar el Código

pg_mysql to pg_mysqli

omassot hace 6 años
padre
commit
ef31161401
Se han modificado 2 ficheros con 55 adiciones y 49 borrados
  1. 53 47
      ajax/datastores.php
  2. 2 2
      js/app.js

+ 53 - 47
ajax/datastores.php

@@ -4,65 +4,71 @@ ini_set('display_startup_errors', 1);
 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
 
 function connect(){
-
-  $link = mysql_connect('127.0.0.1','eligibilite','B3Kg7z6d') or die(mysql_error());
-  mysql_select_db('eligibilite', $link) or die(mysql_error());
+    // $link = mysqli_connect('127.0.0.1','eligibilite','B3Kg7z6d', 'eligibilite', 3306);
+    $link = mysqli_connect('10.5.255.24','eligibilite','B3Kg7z6d', 'eligibilite', 3306);
+    if (mysqli_connect_errno())
+    {
+        echo "Failed to connect to MySQL: " . mysqli_connect_error();
+    }
+    return $link;
 }
 
-function executeQuery($requete) {
-  $resultat = mysql_query($requete) or die(mysql_error());
-
-  if(substr($requete, 0, 6) === 'SELECT'){
-    while($donnees = mysql_fetch_array($resultat)){
-      $resultats[] = $donnees;
+function executeQuery($link, $requete) {
+    
+    $q = mysqli_query($link, $requete);
+    
+    if(substr($requete, 0, 6) === 'SELECT'){
+        while($donnees = mysqli_fetch_array($q)){
+            $results[] = $donnees;
+        }
+        $q->close();
+        if (!isset($results)) {
+            return null;
+        }
+        return $results;
     }
-    if (!isset($resultats)) {
-      return null;
+    else if(substr($requete, 0, 6) === 'INSERT'){
+        $results = mysqli_insert_id($link);
     }
-    return $resultats;
-  }
-  else if(substr($requete, 0, 6) === 'INSERT'){
-    $resultats = mysql_insert_id();
-  }
-  else {
-    $resultats = 'ok';
-  }
-
-  return $resultats;
+    else {
+        $results = True;
+    }
+    
+    return $results;
 }
 
-connect();
+$link = connect();
 
 if(isset($_POST['query'])) {
-  $resultat = executeQuery($_POST['query']);
-  echo json_encode($resultat);
-  return;
+    $resultat = executeQuery($link, $_POST['query']);
+    echo json_encode($resultat);
+    return;
 }
 
 if(isset($_POST['mail'])) {
-  $email = 'ftth@manchenumerique.fr';
-  $bcc   = 'ftth@manchenumerique.fr';
-
-  if(isset($_POST['siteEmail'])) {
-    $email = $_POST['siteEmail'];
-  }
-
-  $headers  = "";
-  $headers .= "Reply-To:".$email."\r\n"."X-Mailer: PHP/".phpversion(). "\r\n";
-  $headers .= "MIME-Version: 1.0"."\r\n";
-  $headers .= "Content-type: text/html; charset=iso-8859-1"."\r\n";
-  $headers .= "Bcc: ".$bcc."\r\n";
-  $headers .= "From: ".utf8_decode("Manche Numérique")." <".$email.">"."\r\n";
-
-  $subject = utf8_decode($_POST['mail']['sujet']);
-  $subject = mb_encode_mimeheader($subject, "UTF-8");
-
-  // Envoi
-  $to = $_POST['mail']['to'];
-  $resultat = mail($to, $subject, utf8_decode($_POST['mail']['message']), $headers, "-f ".$email);
+    $email = 'ftth@manchenumerique.fr';
+    $bcc   = 'ftth@manchenumerique.fr';
+    
+    if(isset($_POST['siteEmail'])) {
+        $email = $_POST['siteEmail'];
+    }
+    
+    $headers  = "";
+    $headers .= "Reply-To:".$email."\r\n"."X-Mailer: PHP/".phpversion(). "\r\n";
+    $headers .= "MIME-Version: 1.0"."\r\n";
+    $headers .= "Content-type: text/html; charset=iso-8859-1"."\r\n";
+    $headers .= "Bcc: ".$bcc."\r\n";
+    $headers .= "From: ".utf8_decode("Manche Numérique")." <".$email.">"."\r\n";
+    
+    $subject = utf8_decode($_POST['mail']['sujet']);
+    $subject = mb_encode_mimeheader($subject, "UTF-8");
+    
+    // Envoi
+    $to = $_POST['mail']['to'];
+    $resultat = mail($to, $subject, utf8_decode($_POST['mail']['message']), $headers, "-f ".$email);
 }
 
 if(isset($resultat)){
-  echo json_encode($resultat);
+    echo json_encode($resultat);
 }
-?>
+?>

+ 2 - 2
js/app.js

@@ -563,7 +563,7 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
     // Si date de début de travaux réelle est renseignée
     if ($scope.results.ftth.date_deb_trav_reel) {
       // Compute Date
-      momentDate = moment($scope.results.ftth.date_deb_trav_reel, 'YYYY-MM-DD');
+      momentDate = moment($scope.results.ftth.date_deb_trav_reel, 'DD/MM/YY');
 
       momentDate.add(nbJoursFTTH, 'days');
 
@@ -580,7 +580,7 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
     ) {
       // Si date de début de travaux prévisionnelle est renseignée
       // Compute Date
-      momentDate = moment($scope.results.ftth.date_abonnement_prev, 'YYYY-MM-DD');
+      momentDate = moment($scope.results.ftth.date_abonnement_prev, 'DD/MM/YY');
       momentDate.add(nbJoursFTTH, 'days');
 
       var semester = '1er';