SHARE
TWEET

Untitled

a guest Sep 3rd, 2018 667 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "root";
  6. $dbname = "db_name";
  7.  
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. if ($conn->connect_error) {
  10.     die("Connection failed: " . $conn->connect_error);
  11. }
  12.  
  13. function HijriToJD($m, $d, $y)
  14. {
  15.     return (int)((11 * $y + 3) / 30) + 354 * $y +
  16.         30 * $m - (int)(($m - 1) / 2) + $d + 1948440 - 385;
  17. }
  18.  
  19. //edit
  20. $sql_select = "SELECT * FROM table_name";
  21.  
  22. //edit
  23. $attributes = ['from_date','to_date'];
  24.  
  25. $result = $conn->query($sql_select);
  26.  
  27. $counter =1 ;
  28.  
  29. print "-------------------------------------------------- \n";
  30.  
  31. if ($result->num_rows > 0) {
  32.     while ($row = $result->fetch_assoc()) {
  33.  
  34.         //edit
  35.         $date_h = $row['from_date'];
  36.  
  37.         if ($date_h != null) {
  38.             $date_h_y = substr($date_h, -8, -4);
  39.             $date_h_m = substr($date_h, -4, -2);
  40.             $date_h_d = substr($date_h, -2);
  41.  
  42.             $date_h_m = intval($date_h_m);
  43.  
  44.             $date = HijriToJD($date_h_m, $date_h_d, $date_h_y);
  45.  
  46.             $new_date = jdtogregorian($date);
  47.             $date = date_create($new_date);
  48.             $date_g = (int)date_format($date, "Ymd");
  49.  
  50.             //edit
  51.             $sql_update_1 = "UPDATE table_name SET from_date_gregorian= '{$date_g}' WHERE from_date='{$row['from_date']}'";
  52.  
  53.  
  54.             echo "*** Row #{$counter} *** \n";
  55.  
  56.             if ($conn->query($sql_update_1) === true) {
  57.                 echo "sql_update_1 Updated Successfully \n";
  58.  
  59.             } else {
  60.                 echo "sql_update_1 Updating Error: \n" . $conn->error;
  61.             }
  62.  
  63.             //edit
  64.             $sql_update_2 = "UPDATE table_name SET from_date_true_type='hijri' WHERE from_date='{$row['from_date']}'";
  65.  
  66.             if ($conn->query($sql_update_2) === true) {
  67.                 echo "sql_update_2 Updated Successfully \n";
  68.  
  69.             } else {
  70.                 echo "sql_update_2 Updating Error: \n" . $conn->error;
  71.             }
  72.         } else {
  73.             echo "*** Row #{$counter} *** \n";
  74.             echo "NULL Value \n";
  75.         }
  76.         print "-------------------------------------------------- \n";
  77.  
  78.         $counter++;
  79.     }
  80.  
  81. } else {
  82.     echo "No Results";
  83. }
  84.  
  85. $conn->close();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top