Commit Diff


commit - 04d41647bc0641805951eb3aa2d72bd2cdfb97ea
commit + d2d3c30b4aecc2fdee9aaa61e48abaeaec2a1fe1
blob - 9e851c0b41c081cb2b798219a4ad9fec8d20f52b
blob + 7afafe038217e23562557f8eda777d1c76df2f7a
--- index.php
+++ index.php
@@ -8,8 +8,8 @@ define("CHARSET", "abcdefghijklmnopqrstuvwxyzABCDEFGHI
 $url = "";
 $link = "";
 $callback = "NO";
+$dbh = new PDO('mysql:host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS);
 
-
 if (DEBUG == 'true') {
         ini_set('display_errors', 1);
         ini_set('display_startup_errors', 1);
@@ -19,16 +19,6 @@ if (DEBUG == 'true') {
         ini_set('display_startup_errors', 0);           
 }
 
-function db_connect() {
-	$dbh = new PDO('mysql:host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS);
-	return $dbh;
-}
-
-function count_urls($dbh) {
-	$sth = $dbh->query("SELECT COUNT(*) FROM ". DB_TABLE);
-	return $sth->fetchColumn();
-}
-
 function generate_short($url, $dbh) {
 	if(!preg_match("/^((https?|ftp)[:\/\/].*\/{2,})/i",$url)) {
 		return false;
@@ -92,8 +82,7 @@ function find_short($hash, $dbh) {
 
 if (isset($_POST['url'])) {
 	if ($_POST['url'] != '' && strlen($_POST['url']) > 0) {
-		$db = db_connect();
-		$link = generate_short($_POST['url'], $db);
+		$link = generate_short($_POST['url'], $dbh);
 	} else {
 		$link = false;
 	}
@@ -103,8 +92,7 @@ if (isset($_GET['hash']) && $_GET['hash'] != '' && str
 	$path = explode('/', $_SERVER['REQUEST_URI']);
 	$uri = $path[count($path)-1];
 	if ($uri != '') {
-		$db = db_connect();
-		$link = find_short($uri, $db);
+		$link = find_short($uri, $dbh);
 		if ($link != '') {
 			header("Cache-Control: no-cache, must-revalidate");
 			header("Expires: Wed, 29 Feb 1984 00:00:00 GMT");
@@ -114,8 +102,8 @@ if (isset($_GET['hash']) && $_GET['hash'] != '' && str
 }
 
 if ($callback == 'NO') {
-	$db = db_connect();
-	$count = count_urls($db);
+	$sth = $dbh->query("SELECT COUNT(*) FROM ". DB_TABLE);
+	$count = $sth->fetchColumn();
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>