Fixed bug where I accessed the database without opening a session

php
Aadhavan Srinivasan 2 years ago
parent 913d53b757
commit 70f91c7586

@ -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');

Loading…
Cancel
Save