Beispiel #1
0
 public function testOperations()
 {
     $test_url = 'http://mindvalley.com';
     $util = new classUtil();
     $conn = $util->getConnection();
     // Check if user can connect to the database
     $this->assertFalse($conn == false);
     // Check if user can read database
     $query = $conn->prepare('SELECT * FROM tbl_urls');
     $results = $query->execute();
     $this->assertEquals(3, $query->columnCount());
     // begin the transaction
     $conn->beginTransaction();
     // Check if user has write access to the database
     $q = "INSERT INTO tbl_urls VALUES(1,'" . $test_url . "',now())";
     $query = $conn->prepare($q);
     $result = $query->execute();
     $this->assertEquals(true, $result);
     $conn->commit();
     // force  commit to get the inserted id	(1)
     // Check if user get correct url from ID
     $id = $util->get_id($test_url);
     // Get id for temp record
     $this->assertEquals(1, $id);
     // Delete the temp record
     $query = $conn->prepare("delete from tbl_urls where id = 1");
     $results = $query->execute();
     $newId = $conn->lastInsertId();
 }
Beispiel #2
0
// MAINTENANCE HISTORY
// DATE         PROGRAMMER AND DETAILS
// 07-12-15     Rahul Sharma    	Original
// 					Added feature to store shorten url mappings to mysql
//					Enabled URL rewrite rules for cleaner URL
// 08-12-15	Rahul Sharma		Fixed Fieldset width
//
//-------------------------------------------------------------------------------------
-->

<?php 
require_once 'includes/classUtil.php';
//  Util class for db and shortcode generation
require_once 'includes/conf.php';
// website configuration
$classUtil = new classUtil();
$response = '';
// if the form has been submitted
if (isset($_POST['url'])) {
    // escape bad characters from the user's url
    $url = trim(mysql_escape_string($_POST['url']));
    // add the url to the database
    if ($classUtil->insert_url($url)) {
        if (REWRITE) {
            $url = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['PHP_SELF']) . '/' . $classUtil->get_id($url);
        } else {
            $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . '?id=' . $classUtil->get_id($url);
        }
        $response = '<p>Short URL is: <a href="' . $url . '">' . $url . '</a></p>';
    } else {
        $response = '<p>Short URL could not be created!</p>';