Skip to content

Instantly share code, notes, and snippets.

@mschultheiss83
Forked from sang4lv/gist:4499788
Created January 10, 2013 06:03
Show Gist options
  • Save mschultheiss83/4499800 to your computer and use it in GitHub Desktop.
Save mschultheiss83/4499800 to your computer and use it in GitHub Desktop.
MySQLi example
<?php
function processURL($originalURL, $array) {
$base = "http://example.com";
$avail = "";
$link = new mysqli($host, $user, $pass, $daba);
if(mysqli_connect_errno()) {
die("Connection failed" . mysqli_connect_error());
}
for($i = 0; $i < count($array); $i++) {
$avail = $base . $array[$i];
$query = "SELECT originalURL FROM url WHERE shortURL = {$avail}";
if(($link->query($query)) == 0) {
break; //If empty, use it
}
}
if($avail != "") {
$link->query("INSERT INTO url VALUES(, {$originalURL}, {$avail})");
if($link->errno() <> 0) {
$link->close();
return $avail;
}
}
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment