Skip to content

Instantly share code, notes, and snippets.

@kyob
Created January 26, 2017 10:49
Show Gist options
  • Save kyob/a920ff7a9c8c5ba198e8e3b559982e86 to your computer and use it in GitHub Desktop.
Save kyob/a920ff7a9c8c5ba198e8e3b559982e86 to your computer and use it in GitHub Desktop.
<?php
$mysqli_remote = new mysqli("rhost", "rlogin", "rpass", "rdb");
mysqli_local = new mysqli("lhost", "lroot", "lpass", "ldb");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sqlt = "TRUNCATE TABLE radcheck";
$mysqli_local->query($sqlt);
$query = "SELECT id, pin FROM customersview WHERE ssn != '' AND deleted = 0 AND email != '' AND consentdate > 0 ORDER BY id";
$ile=0;
if ($result = $mysqli_remote->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
$sql = "INSERT INTO radcheck (id,username,attribute,op,value) VALUES (NULL, ".$row['id'].", 'Cleartext-Password', ':=', ".$row['pin'].");";
if(!$mysqli_local->query($sql)) {
echo "insert failed, error: ", $mysqli_local->error;
}
$ile++;
}
/* free result set */
$result->free();
}
echo "Affected rows (INSERT): ".$ile."\n";
/* close connection */
$mysqli_remote->close();
$mysqli_local->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment