Hello Stackoverflow community!
I have a problem i have this script (below) and when i access the file with right switch cases i become a white screen. the first script doesnt work the seconds works fine. i isolated the error in my opinion: the sql statement (table and columns exist)
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "regressiontest";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
switch($operation){
case "managerList": {
$stmt = $conn->query("
SELECT
*
FROM
regressiontest.campaign_run;");
} break;
}
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$output = $stmt->fetchAll();
switch($compute){
case "json": {
echo json_encode($output, JSON_NUMERIC_CHECK);
}
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
And this cases works fine
<?php
//check for error output
if(isset($_GET['error'])){
if($_GET['error'] == "false"){
error_reporting(0);
} else if($_GET['error'] == "true"){
ini_set('error_reporting', E_ALL);
} else {
error_reporting(0);
}
} else {
error_reporting(0);
}
//check for timelimit
if(isset($_GET['timelimit'])){ set_time_limit($_GET['timelimit']); } else { set_time_limit(0); }
//check for operation
if(isset($_GET['operation'])){ $operation = $_GET['operation']; } else { exit; }
//check for compute
if(isset($_GET['compute'])){ $compute = $_GET['compute']; } else { exit; }
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "regressiontest";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
switch($operation){
case "managerFilter": {
$stmt = $conn->prepare("
SELECT
GROUP_CONCAT(DISTINCT (campaign_name) order by campaign_name asc) AS uniqueCampaignName,
GROUP_CONCAT(DISTINCT (test_type) order by test_type asc) AS uniqueTestType,
GROUP_CONCAT(DISTINCT (testee) order by testee asc) AS uniqueTestee,
GROUP_CONCAT(DISTINCT (testee_version) order by testee_version asc) AS uniqueTesteeVersion
FROM
regressiontest.campaign_run;
");
} break;
case "testcaseStatistics": {
$testcaseId = $_GET['testcaseId'];
$stmt = $conn->prepare("
SELECT
terminal,
AVG(runtime_ms) AS avg_runtime_ms,
COUNT(id) AS count_runs,
COUNT(CASE
WHEN result = 0 THEN 1
ELSE NULL
END) AS passed_runs,
COUNT(CASE
WHEN result = 1 THEN 1
ELSE NULL
END) AS failed_runs,
COUNT(id) - COUNT(CASE
WHEN result = 0 THEN 1
ELSE NULL
END) - COUNT(CASE
WHEN result = 1 THEN 1
ELSE NULL
END) AS aborted_runs,
COUNT(CASE
WHEN result = 0 THEN 1
ELSE NULL
END) / COUNT(id) * 100 AS success_rate,
COUNT(CASE
WHEN result = 1 THEN 1
ELSE NULL
END) / COUNT(id) * 100 AS fail_rate
FROM
tc_result
WHERE
tc_id = ".$testcaseId."
GROUP BY terminal
");
} break;
case "testcaseRuns": {
$testcaseId = $_GET['testcaseId'];
$stmt = $conn->prepare("
SELECT
tc_result.campaign_id,
tc_result.tc_id,
tc_result.id,
tc_result.terminal,
tc_result.createdate,
tc_result.runtime_ms,
tc_result.trx,
tc_result.result,
campaign_run.testee
FROM
tc_result
INNER JOIN
campaign_run ON tc_result.campaign_id = campaign_run.id
WHERE
tc_id = ".$testcaseId."
");
}
}
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$output = $stmt->fetchAll();
switch($compute){
case "json": {
echo json_encode($output, JSON_NUMERIC_CHECK);
}
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>