Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $user = "username";
- $pass= "secret";
- $pu239_db = "dev";
- $old_db = "temp";
- $host = "localhost";
- if ($user === 'username' || $pass === 'secret') {
- die("please edit this file\n");
- }
- $link = mysqli_connect("$host", "$user", "$pass", "$pu239_db") or die("Error " . mysqli_error($link));
- $sql = "SELECT * FROM $old_db.user ORDER BY userid";
- $rs = $link->query($sql);
- $i = 0;
- while ($row = mysqli_fetch_assoc($rs)) {
- $username = sqlesc($row['username']);
- $email = sqlesc($row['email']);
- $added = (int)$row['joindate'];
- $last_login = (int)time();
- $last_access = (int)time();
- $time_offset = sqlesc($row['timezoneoffset']);
- $birthday = sqlesc($row['birthday_search']);
- $ip = '0x' . bin2hex(inet_pton($row['ipaddress']));
- $passhash = sqlesc(bin2hex(random_bytes(32)));
- $torrent_pass= sqlesc(bin2hex(random_bytes(32)));
- $auth = sqlesc(bin2hex(random_bytes(32)));
- $apikey = sqlesc(bin2hex(random_bytes(32)));
- $status = sqlesc('confirmed');
- $sql = "INSERT IGNORE INTO users (username, email, added, last_login, last_access, time_offset, birthday, ip, passhash, torrent_pass, auth, apikey, status)
- VALUES ($username, $email, $added, $last_login, $last_access, $time_offset, $birthday, $ip, $passhash, $torrent_pass, $auth, $apikey, $status)";
- echo $sql . "\n";
- if ($link->query($sql)) {
- $i++;
- }
- }
- echo "$i users imported\n";
- function sqlesc($x)
- {
- global $link;
- if (is_integer($x)) return (int)$x;
- return sprintf('\'%s\'', mysqli_real_escape_string($link, $x));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement