From 70f91c75867bf136ad277c879fad93205ee961a2 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 12 Jun 2023 15:28:30 -0500 Subject: [PATCH] Fixed bug where I accessed the database without opening a session --- result.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/result.php b/result.php index 25f7fb0..29dd660 100644 --- a/result.php +++ b/result.php @@ -32,6 +32,7 @@ use Casssandra; $cluster = Cassandra::cluster()->withPersistentSessions(true)->build(); $keyspace = 'glink'; +$session = $cluster->connect($keyspace); $url = $_GET["url"]; $matches = preg_match('/^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$/',$url); @@ -55,7 +56,7 @@ if ($shortlink != '') { $shortlink = $rand_string; /* Check if shortlink is already taken by querying the database */ - $statement = $session->prepare('SELECT url FROM data WHERE id=?'); + $statement = $session->prepare('SELECT url FROM data WHERE shortlink=? ALLOW FILTERING'); $result = $session->execute($statement,array('arguments' => array($shortlink))); if ($result->count() != 0) { @@ -64,8 +65,6 @@ if ($shortlink != '') { } -$session = $cluster->connect($keyspace); - //$statement = new Cassandra\SimpleStatement('SELECT name FROM data WHERE id=5'); $statement = $session->prepare('SELECT url FROM data WHERE shortlink=? ALLOW FILTERING');