zeus1999999 Posted February 2, 2017 Share Posted February 2, 2017 Hello 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 <?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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/303088-php-pdo-empty-page/ Share on other sites More sharing options...
requinix Posted February 2, 2017 Share Posted February 2, 2017 switch($operation){Where is $operation being set? No $operation means no $stmt and so the $stmt->execute();will fail (calling a method on a non-object) and PHP will die. If you aren't seeing that error message then your environment is not correctly set up for PHP development. Find your php.ini and change two settings: error_reporting = -1 display_errors = onThen restart your webserver and try that first script again. Quote Link to comment https://forums.phpfreaks.com/topic/303088-php-pdo-empty-page/#findComment-1542240 Share on other sites More sharing options...
zeus1999999 Posted February 2, 2017 Author Share Posted February 2, 2017 switch($operation){Where is $operation being set? No $operation means no $stmt and so the $stmt->execute();will fail (calling a method on a non-object) and PHP will die. If you aren't seeing that error message then your environment is not correctly set up for PHP development. Find your php.ini and change two settings: error_reporting = -1 display_errors = onThen restart your webserver and try that first script again. <?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 "managerList": { $stmt = $conn->prepare(" SELECT * 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; ?> full script only case managerList wont work Quote Link to comment https://forums.phpfreaks.com/topic/303088-php-pdo-empty-page/#findComment-1542243 Share on other sites More sharing options...
requinix Posted February 2, 2017 Share Posted February 2, 2017 PHP won't show a white screen without some indication as to what went wrong. Did you do the settings thing I said? Also, you've missed the point of how prepared statements work. Don't put values straight into the queries: "WHERE tc_id = ".$testcaseIdUse a placeholder, like :testcaseId "WHERE tc_id = :testcaseId"and then use the actual value with either bindParam() or execute(). The former would be easier for your code. $stmt = "..."; $stmt->bindParam(":testcaseId", $testCaseId, PDO::PARAM_INT); Quote Link to comment https://forums.phpfreaks.com/topic/303088-php-pdo-empty-page/#findComment-1542246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.