Example #1
0
<!-- Script for extending table of short IDs -->

<?php 
// Administrator Page used to extend the Link characters used.
// autoload the database class so we can easily connect to the database as required.
function __autoload($class_name)
{
    require $class_name . '.php';
}
$datab = new DataBaseConnection();
$datab->connectSelect();
// Array to hold the characters for the algorithm
$arr = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
// Array to hold number of possible links per characters in the shortlink
$arrLinks = array(1 => 62, 2 => 3906, 3 => 242234, 4 => 15018570);
// Function to calculate the quantities to be displayed.
function calculateQuantities($datab, $arrLinks, &$linksTotal, &$linksAvailable, &$linksTotal, &$linksUsed, &$linksNextExtend)
{
    // Get the max link from the link table, this is the number of links in the database.
    $sql = "SELECT max(id) FROM link";
    $result = mysqli_query($datab->link, $sql);
    // Check if the query didn't run
    if (!$result) {
        echo "Could not create new link, database error" . mysql_error();
        die;
    } else {
        $row = mysqli_fetch_array($result, MYSQLI_NUM);
        $linksUsed = $row[0];
    }
    // Find the available links by getting the max id from the linklookup table and taking the used links away from it.
    $sql = "SELECT max(id) FROM linklookup";