connect_error) { die("Connection failed: " . $db->connect_error); } // Change db to "test" db //// mysqli_select_db($db, "test"); $Arabic= 'SET CHARACTER SET utf8'; mysqli_query($db,$Arabic) or die ('Can\'t charset in DataBase'); $db->set_charset("utf8"); $get_from_old = mysqli_query($db, "SELECT `booking_users`.`id`, `booking_users`.`name_utf`, `booking_users`.`rg_date`, `booking_users`.`mobile`, `booking_users`.`age`, `offres`.`name_ar_utf` FROM `booking_users` LEFT JOIN `offres` ON `booking_users`.`offre` = `offres`.`id` WHERE (`booking_users`.`mobile` LIKE '9665%' AND CHAR_LENGTH(`booking_users`.`mobile`) = 12) OR (`booking_users`.`mobile` LIKE '5%' AND CHAR_LENGTH(`booking_users`.`mobile`) = 9)" ); $old_data= array(); if (mysqli_num_rows($get_from_old) > 0) { while ($row_from_old = mysqli_fetch_assoc($get_from_old)) { array_push($old_data, array( 'id' => $row_from_old['id'], 'name' => $row_from_old['name_utf'], 'mobile' => $row_from_old['mobile'], 'age' => $row_from_old['age'], 'name_ar_utf' => $row_from_old['name_ar_utf'] . ' مؤرشف', 'date' => $row_from_old['rg_date'], )); } } echo ' / after / '; $name_db = "aqdamypanel_aqdamy"; $host_db = "localhost"; $user_db = "aqdamypanel_mysql"; $pass_db = "AST4dxy6vEsi"; $db = new mysqli($host_db, $user_db, $pass_db, $name_db); if ($db->connect_error) { die("Connection failed: " . $db->connect_error); } // Change db to "test" db //// mysqli_select_db($db, "test"); $Arabic= 'SET CHARACTER SET utf8'; mysqli_query($db,$Arabic) or die ('Can\'t charset in DataBase'); $db->set_charset("utf8"); $not_in = ''; $itis_in = ''; foreach ($old_data as $i) { $old_data_temp_id = $i['id']; $old_data_temp_name = $i['name']; $old_data_temp_mobile = $i['mobile']; $old_data_temp_age = $i['age']; $old_data_temp_date = $i['date']; $name_ar_utf = $i['name_ar_utf']; if ($name_ar_utf == ' مؤرشف') { $name_ar_utf = 'غير محدد'; } if (strlen($old_data_temp_mobile) == 12) { $old_data_temp_mobile = substr($old_data_temp_mobile, 3); } $check = mysqli_query($db, "SELECT `id` FROM `tretment` WHERE `number` = '$old_data_temp_mobile' AND `commercial_register_id` = '2'" ); if (mysqli_num_rows($check) > 0) { $not_in .= $old_data_temp_id . ', '; } else { $itis_in .= " ( '$old_data_temp_name', '$old_data_temp_mobile', '$old_data_temp_age', (SELECT `id` FROM `an_employee_offer` WHERE `name` = '$name_ar_utf'), '2', '$old_data_temp_date', '1', '2' ),"; } } $myfile = fopen("booking_users_found.txt", "w") or die("Unable to open file!"); $txt = $not_in; fwrite($myfile, $txt); fclose($myfile); $myfile = fopen("booking_users_not_found.txt", "w") or die("Unable to open file!"); $txt = "INSERT INTO `tretment`(`name`, `number`, `age`, `an_employee_offer_id`, `commercial_register_id`, `date_time`, `user_id`, `activation_id`) VALUES"; $txt .= $itis_in; fwrite($myfile, $txt); fclose($myfile); } ?>