Skip to content

Commit

Permalink
Make code compatible with PHP-v5
Browse files Browse the repository at this point in the history
  • Loading branch information
ttsudipto committed Jul 14, 2022
1 parent 96c0da4 commit d90b20f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 23 deletions.
25 changes: 22 additions & 3 deletions advance_search_result.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ function createParamString($keys) {
}
return $typeString;
}

function refValues($arr){
$refs = array();
for($i=0; $i<count($arr); ++$i)
$refs[$i] = &$arr[$i];
return $refs;
}

$predicateCount = $_POST["total_count"];
$logicalOperators = array();
Expand All @@ -157,10 +164,22 @@ function createParamString($keys) {

$conn = connect();
$stmt = $conn->prepare($query);
$stmt->bind_param($paramString, ...$values);

array_unshift($values, $paramString);
call_user_func_array(
array($stmt, "bind_param"),
refValues($values)
);
$stmt->execute();
$result = $stmt->get_result();
$rows = $result->fetch_all(MYSQLI_ASSOC);

// $stmt->bind_param($paramString, ...$values);
// $stmt->execute();
// $result = $stmt->get_result();
// $rows = $result->fetch_all(MYSQLI_ASSOC);
$rows = execute_and_fetch_assoc($stmt);
// foreach($rows as $row) {
// echo implode(",", $row)."<br/>";
// }
$rowsJSON = json_encode($rows);
// echo $result->num_rows." ".$result->field_count."<br/>";

Expand Down
21 changes: 12 additions & 9 deletions bioproject_id.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@

$bioprojectStmt = $conn->prepare($bioprojectQuery);
$bioprojectStmt->bind_param("s", $bioprojectID);
$bioprojectStmt->execute();
$bioprojectResult = $bioprojectStmt->get_result();
// $bioprojectStmt->execute();
// $bioprojectResult = $bioprojectStmt->get_result();
// echo $bioprojectResult->num_rows." ".$bioprojectResult->field_count."<br/><br/>";
$bioprojectRows = execute_and_fetch_assoc($bioprojectStmt);
$bioprojectStmt->close();

$runStmt = $conn->prepare($runQuery);
$runStmt->bind_param("s", $bioprojectID);
$runStmt->execute();
$runResult = $runStmt->get_result();
// $runStmt->execute();
// $runResult = $runStmt->get_result();
// echo $runResult->num_rows." ".$runResult->field_count."<br/><br/>";
$runRows = $runResult->fetch_all(MYSQLI_ASSOC);
// $runRows = $runResult->fetch_all(MYSQLI_ASSOC);
$runRows = execute_and_fetch_assoc($runStmt);
$runRowsJSON = json_encode($runRows);
$runStmt->close();

Expand Down Expand Up @@ -65,13 +67,13 @@

<div class = "section_middle">
<?php
if ($bioprojectResult->num_rows < 1) {
if (count($bioprojectRows) < 1) {
echo "<center><p>Error !!! BioProject ID: ".$bioprojectID." does not exist in the database.</p></center>";
} else {
echo "<center><h3>BioProject ID: ".$bioprojectID."</h3></center>";
echo "<table class=\"details\" border=\"1\">";
echo "<tr><th>Attribute</th><th>Value</th></tr>";
while ($row = $bioprojectResult->fetch_assoc()){
foreach($bioprojectRows as $row){
foreach ($allBioProjectAttributes as $name=>$fname) {
if ($name !== "BioProject") {
echo "<tr>";
Expand All @@ -86,8 +88,9 @@
echo "<td style=\"width:60%\">";
foreach($subgroups as $sg) {
$diseaseStmt->bind_param("s", $sg);
$diseaseStmt->execute();
$disease = $diseaseStmt->get_result()->fetch_all(MYSQLI_ASSOC);
// $diseaseStmt->execute();
// $disease = $diseaseStmt->get_result()->fetch_all(MYSQLI_ASSOC);
$disease = execute_and_fetch_assoc($diseaseStmt);
echo $disease[0]["Grp"]." &rarr; ".$sg."<br/>";
}
echo "</td>";
Expand Down
40 changes: 40 additions & 0 deletions db.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,44 @@ function connect() {
function closeConnection($conn) {
$conn->close();
}

function execute_and_fetch_assoc($stmt, $types = false, $params = false) {
if (!$stmt->execute()) {
return false;
}
$stmt->store_result();

// get column names
$metadata = $stmt->result_metadata();
$fields = $metadata->fetch_fields();

$results = [];
$ref_results = [];
foreach($fields as $field){
$results[$field->name]=null;
$ref_results[]=&$results[$field->name];
}

call_user_func_array(array($stmt, 'bind_result'), $ref_results);

$data = array();
$i=0;
while ($stmt->fetch()) {
$c = 0;
$new_res = array();
foreach($results as $f => $v) {
$new_res[$f] = $v;
$c++;
}
// echo implode(",", $new_res);
array_push($data, $new_res);
}

// echo count($data);
// foreach($data as $d)
// echo implode(",", $d)."<br/>";

$stmt->free_result();
return $data;
}
?>
7 changes: 4 additions & 3 deletions disease_wise_bioprojects.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
$bioprojectStmt = $conn->prepare($bioprojectQuery);
$disease = "%".$disease."%";
$bioprojectStmt->bind_param("s", $disease);
$bioprojectStmt->execute();
$bioprojectResult = $bioprojectStmt->get_result();
// $bioprojectStmt->execute();
// $bioprojectResult = $bioprojectStmt->get_result();
// echo $bioprojectResult->num_rows." ".$bioprojectResult->field_count."<br/><br/>";
$rows = $bioprojectResult->fetch_all(MYSQLI_ASSOC);
// $rows = $bioprojectResult->fetch_all(MYSQLI_ASSOC);
$rows = execute_and_fetch_assoc($bioprojectStmt);
$rowsJSON = json_encode($rows);
$bioprojectStmt->close();
closeConnection($conn);
Expand Down
7 changes: 4 additions & 3 deletions get_choropleth_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
$conn = connect();

$choroplethStmt = $conn->prepare($choroplethQuery);
$choroplethStmt->execute();
$choroplethResult = $choroplethStmt->get_result();
// $choroplethStmt->execute();
// $choroplethResult = $choroplethStmt->get_result();
// echo $bioprojectResult->num_rows." ".$bioprojectResult->field_count."<br/><br/>";
$rows = $choroplethResult->fetch_all(MYSQLI_ASSOC);
// $rows = $choroplethResult->fetch_all(MYSQLI_ASSOC);
$rows = execute_and_fetch_assoc($choroplethStmt);
$rowsJSON = json_encode($rows);
$choroplethStmt->close();
closeConnection($conn);
Expand Down
11 changes: 6 additions & 5 deletions run_id.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
$conn = connect();
$stmt = $conn->prepare($query);
$stmt->bind_param("s", $runID);
$stmt->execute();
$result = $stmt->get_result();
// $stmt->execute();
// $result = $stmt->get_result();
// echo $result->num_rows." ".$result->field_count."<br/>";
// $rows = $result->fetch_all(MYSQLI_ASSOC);
$rows = execute_and_fetch_assoc($stmt);
$stmt->close();
closeConnection($conn);
?>
Expand Down Expand Up @@ -47,13 +48,13 @@

<div class = "section_middle">
<?php
if ($result->num_rows < 1) {
if (count($rows) < 1) {
echo "<center><p>Error !!! Run ID: ".$runID." does not exist in the database.</p></center>";
} else {
echo "<center><h3>Run ID: ".$runID."</h3></center><hr/><br/>";
echo "<table class=\"details\" border=\"1\">";
echo "<tr><th>Attribute</th><th>Value</th></tr>";
while ($row = $result->fetch_assoc()){
foreach($rows as $row){
foreach ($allRunAttributes as $name=>$fname) {
if ($name !== "Run") {
echo "<tr>";
Expand All @@ -70,6 +71,6 @@
}
?>

</div>
<br/>
</body>
</html>

0 comments on commit d90b20f

Please sign in to comment.