-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path22-23-mcodes.php
45 lines (36 loc) · 1.25 KB
/
22-23-mcodes.php
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
<?php
// Database connection parameters
$host = "localhost";
$username = "multimat_final";
$password = "multimat_final";
$database = "multimat_multimat";
// Establishing a connection to the database
$con = mysqli_connect($host, $username, $password, $database);
// Check if the connection was successful
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
// SQL query to fetch the user_mcode column where user_registeredon contains 2022 or 2023
$query = "SELECT user_mcode FROM mat_user WHERE user_registeredon LIKE '%2022%' OR user_registeredon LIKE '%2023%' ORDER BY user_registeredon";
// Execute the query
$result = mysqli_query($con, $query);
// Check if the query returned any results
if (mysqli_num_rows($result) > 0) {
// File to save the results
$filename = "user-22-23-mcode.txt";
$file = fopen($filename, "w");
if (!$file) {
die("Failed to create or open the file.");
}
// Fetch the rows and write each user_mcode to the file
while ($row = mysqli_fetch_assoc($result)) {
fwrite($file, $row['user_mcode'] . PHP_EOL);
}
fclose($file);
echo "Data successfully dumped into $filename";
} else {
echo "No matching records found.";
}
// Close the database connection
mysqli_close($con);
?>