-
-
Save mschultheiss83/4499800 to your computer and use it in GitHub Desktop.
MySQLi example
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
<?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