Created
January 11, 2013 15:20
-
-
Save sang4lv/4511439 to your computer and use it in GitHub Desktop.
Windows Azure MySQL database connection using PHP
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 | |
| echo xiaoxiaoURL($_GET['url']); | |
| function xiaoxiaoURL($url) { | |
| $base64 = array( | |
| 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', | |
| 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', | |
| 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', | |
| 'n', 'm', '0', '9', '8', '7', '6', '5' | |
| ); | |
| $url = urldecode($url); | |
| $output = array(); | |
| $hex = md5($input); | |
| $subHexLen = strlen($hex) / 8; | |
| for ($i = 0; $i < $subHexLen; $i++) { | |
| $subHex = substr ($hex, $i * 8, 8); | |
| $int = 0x3FFFFFFF & (1 * ('0x' . $subHex)); | |
| $out = ''; | |
| for ($j = 0; $j < 6; $j++) { | |
| $val = 0x0000001F & $int; | |
| $out .= $base32[$val]; | |
| $int = $int >> 5; | |
| } | |
| $output[] = $out; | |
| } | |
| return processURL($url, $output); | |
| } | |
| function processURL($originalURL, $array) { | |
| $base = "http://xxu.windowsazure.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