Untitled
unknown
plain_text
a year ago
1.3 kB
10
Indexable
<?php
// Database connection details
$host = 'localhost';
$dbname = 'your_database';
$username = 'your_username';
$password = 'your_password';
// Create a new PDO instance
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Could not connect to the database: " . $e->getMessage());
}
// Query to retrieve the source_id meta key and corresponding user_id
$query = "
SELECT um.user_id, um.meta_value AS source_id
FROM user_meta um
WHERE um.meta_key = 'source_id'
";
try {
// Execute the query
$stmt = $pdo->query($query);
// Fetch all results
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Prepare the update query
$updateQuery = "
UPDATE target_table
SET user_id = :user_id
WHERE source_id = :source_id
";
$updateStmt = $pdo->prepare($updateQuery);
// Loop through the results and update the target table
foreach ($results as $row) {
$updateStmt->execute([
':user_id' => $row['user_id'],
':source_id' => $row['source_id']
]);
}
echo "Update completed successfully.";
} catch (PDOException $e) {
echo "An error occurred: " . $e->getMessage();
}
?>
Editor is loading...
Leave a Comment