Skip to content

Instantly share code, notes, and snippets.

@puzanov
Created August 14, 2017 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puzanov/042dd641cc16c9279abb054db6e5360f to your computer and use it in GitHub Desktop.
Save puzanov/042dd641cc16c9279abb054db6e5360f to your computer and use it in GitHub Desktop.
types migtation
cat types.php
<?php
function getDB() {
$mysqli = new mysqli("mysql", "", "", "");
if (mysqli_connect_errno()) {
printf("Mysql connection error: %s\n", mysqli_connect_error());
exit();
}
return $mysqli;
}
$m = getDB();
if (!$result = $m->query("SELECT * FROM `types` WHERE hostname REGEXP '^www\.'")) {
echo "Sorry, the website is experiencing problems.";
exit;
}
while ($type = $result->fetch_assoc()) {
$type['hostname'] = preg_replace("/^www\./", "", $type['hostname']);
$q = "INSERT INTO `types` (`hostname`, `hosttype`) VALUES (?, ?);";
if ($stmt = $m->prepare($q)) {
$stmt->bind_param("ss",
$type['hostname'],
$type['hosttype']
);
if (!$stmt->execute()) {
var_dump($stmt->error);
} else {
print("Saved\n");
}
$stmt->close();
} else {
var_dump($m->error);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment