Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "root";
- $dbname = "db_name";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- function HijriToJD($m, $d, $y)
- {
- return (int)((11 * $y + 3) / 30) + 354 * $y +
- 30 * $m - (int)(($m - 1) / 2) + $d + 1948440 - 385;
- }
- //edit
- $sql_select = "SELECT * FROM table_name";
- //edit
- $attributes = ['from_date','to_date'];
- $result = $conn->query($sql_select);
- $counter =1 ;
- print "-------------------------------------------------- \n";
- if ($result->num_rows > 0) {
- while ($row = $result->fetch_assoc()) {
- //edit
- $date_h = $row['from_date'];
- if ($date_h != null) {
- $date_h_y = substr($date_h, -8, -4);
- $date_h_m = substr($date_h, -4, -2);
- $date_h_d = substr($date_h, -2);
- $date_h_m = intval($date_h_m);
- $date = HijriToJD($date_h_m, $date_h_d, $date_h_y);
- $new_date = jdtogregorian($date);
- $date = date_create($new_date);
- $date_g = (int)date_format($date, "Ymd");
- //edit
- $sql_update_1 = "UPDATE table_name SET from_date_gregorian= '{$date_g}' WHERE from_date='{$row['from_date']}'";
- echo "*** Row #{$counter} *** \n";
- if ($conn->query($sql_update_1) === true) {
- echo "sql_update_1 Updated Successfully \n";
- } else {
- echo "sql_update_1 Updating Error: \n" . $conn->error;
- }
- //edit
- $sql_update_2 = "UPDATE table_name SET from_date_true_type='hijri' WHERE from_date='{$row['from_date']}'";
- if ($conn->query($sql_update_2) === true) {
- echo "sql_update_2 Updated Successfully \n";
- } else {
- echo "sql_update_2 Updating Error: \n" . $conn->error;
- }
- } else {
- echo "*** Row #{$counter} *** \n";
- echo "NULL Value \n";
- }
- print "-------------------------------------------------- \n";
- $counter++;
- }
- } else {
- echo "No Results";
- }
- $conn->close();
Add Comment
Please, Sign In to add comment