Created
August 14, 2017 10:08
-
-
Save puzanov/042dd641cc16c9279abb054db6e5360f to your computer and use it in GitHub Desktop.
types migtation
This file contains hidden or 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
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