Created
June 28, 2010 11:57
-
-
Save balibali/455750 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dry_run = false; | |
// http://php.net/manual/ref.pdo-mysql.connection.php | |
$pdo_dsn = 'mysql:xxx'; | |
$pdo_user = 'xxx'; | |
$pdo_pass = 'xxx'; | |
$dbh = new PDO($pdo_dsn, $pdo_user, $pdo_pass); | |
$sth = $dbh->query('SELECT id FROM member WHERE is_active = 1 AND is_login_rejected = 0 ORDER BY id'); | |
$ids = $sth->fetchAll(PDO::FETCH_COLUMN); | |
$results = array(); | |
$max_id = max($ids); | |
foreach ($ids as $i) { | |
for ($j = $i + 1; $j <= $max_id; $j++) { | |
if (!in_array($j, $ids)) continue; | |
$results[] = sprintf('(%d,%d,1,0)', $i, $j); | |
$results[] = sprintf('(%d,%d,1,0)', $j, $i); | |
} | |
} | |
$query1 = 'TRUNCATE TABLE member_relationship'; | |
$query2 = 'INSERT INTO member_relationship(member_id_to,member_id_from,is_friend,is_friend_pre) VALUES ' . implode(',', $results); | |
if ($dry_run) { | |
echo $query1, ';', PHP_EOL; | |
echo $query2, ';', PHP_EOL; | |
} else { | |
$dbh->query($query1); | |
$dbh->query($query2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment