****NOTE****
I have a workaround for this, listed at the end. I'm self taught (OTJ) and am curious on why this works on one box and not another..
I have the below function, in a functions file, that works locally on my MAMP Server. But when I upload it to our Web Dev (Linux) server I can't get past loading the functions file, so nothing opens..
MAMP PHP: 5.4.10
Web Server: 5.3.3
The line that's getting me is this. Commenting it out things load fine for ALL pages. I just can't display this value..
//Get results from returned object $get_issue_info_value = $get_issue_info->fetch()['issue'];
Full function:
function get_issue_info($id){ //echo '<script type="text/javascript">alert("inside get_issue_info function - the ID: '.$id.'")</script>'; try{ global $db; //Prepare Query $get_issue_info = $db->prepare("select issue from website_issues where id = :id"); //Bind Values $get_issue_info->bindValue(':id', $id, PDO::PARAM_STR); //execute $get_issue_info->execute(); //Get results from returned object $get_issue_info_value = $get_issue_info->fetch()['issue']; /* * Debug: show returned value * echo '<script type="text/javascript">alert("Debug - Show value: '.$get_issue_info_value.'")</script>'; * */ //Return return $get_issue_info_value; } catch(PDOException $e) { echo 'ERROR inside the get_issue_info function: ' . $e->getMessage(); } }
For testing I ran the below code in the functions file locally, using MAMP, I get:
$get_issue_info_value = $get_issue_info->fetchAll(PDO::FETCH_ASSOC);
Result:
Array
(
[0] => Array
(
[issue] => A new issue Added
)
)
$get_issue_info_value = $get_issue_info->fetch()['issue'];
Result:
A new issue Added
FIX - this works locally and on the Web Dev server
Fix in the functions file:
//Get results from returned object //$get_issue_info_value = $get_issue_info->fetch(['issue']); $get_issue_info_value = $get_issue_info->fetchAll(PDO::FETCH_ASSOC);
Fix in the php file:
$issue_info = get_issue_info($id); /** Check the returned value*/ echo "<pre>"; print_r($issue_info); echo "</pre>"; $issue = $issue_info[0]['issue']; echo "<hr>"; /** Check the returned value*/ echo "Issue: " . $issue;