54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
$TEST = 1;
|
|
|
|
// Create a new mysqli instance
|
|
if ($TEST) {
|
|
$mysqli = new mysqli("192.168.1.6", "phowell", "rolley34", "db");
|
|
} else {
|
|
$mysqli = new mysqli("localhost", "phowell", "p^howell", "PeterDB");
|
|
}
|
|
|
|
// Check for connection error
|
|
if ($mysqli->connect_error) {
|
|
die("Connection failed: " . $mysqli->connect_error);
|
|
}
|
|
|
|
// Start a query to get rows ordered by 'goo'
|
|
$query = "SELECT * FROM conf_users ORDER BY goo DESC LIMIT 5000";
|
|
$result = $mysqli->query($query);
|
|
|
|
// Key: goo, Value: id
|
|
$goo_to_id = array();
|
|
|
|
// Iterating through each result
|
|
while ($row = $result->fetch_assoc()) {
|
|
$id = $row['id'];
|
|
$goo = $row['goo'];
|
|
|
|
// Check if an entry exists for this 'goo'
|
|
if (array_key_exists($goo, $goo_to_id)) {
|
|
// Save lower and higher id
|
|
$lower_id = min($id, $goo_to_id[$goo]);
|
|
$higher_id = max($id, $goo_to_id[$goo]);
|
|
|
|
echo "(test) UPDATE conf_signups SET user={$lower_id} WHERE user={$higher_id}\n<br>\n";
|
|
|
|
// Prepare an update statement and execute
|
|
|
|
if (! $TEST) {
|
|
$update_stmt = $mysqli->prepare("UPDATE conf_signups SET user=? WHERE user=?");
|
|
$update_stmt->bind_param("ii", $lower_id, $higher_id);
|
|
$update_stmt->execute();
|
|
echo "UPDATE conf_signups SET user={$lower_id} WHERE user={$higher_id}\n<br>\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
$goo_to_id[$goo] = $id;
|
|
}
|
|
}
|
|
|
|
// Closing the database connection
|
|
$mysqli->close();
|