rizmah Posted September 17, 2014 Share Posted September 17, 2014 So I am hosting from 000webhost and when I goto my index.php it shows a blank white screen. I view the source of the screen and it said Fatal error: Call to a member function fetchColumn() on a non-object in /home/*REMOVED*/public_html/staff/header.php on line 2 So I check this line of code and it's... <title> <?php echo $odb->query("SELECT `Tab` FROM `SiteConfig` LIMIT 1")->fetchColumn(0); ?> </title> I don't know how to fix it? I am using phpmyadmin too and have siteconfig in there. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/291126-how-do-i-fix-this/ Share on other sites More sharing options...
Psycho Posted September 17, 2014 Share Posted September 17, 2014 Most likely your query is failing. The error is telling you that the method fetchColumn() is trying to be executed against a non-object. In that line of code there is "$odb->query()" being used to execute a query and then "->fetchColumn(0)" is attempting to be executed against that result. If the query fails there is nothing for fetchColumn() to execute against. You have no error handling in that code. IMO, you should never assume queries will pass. You should always include error handling to at least provide the user some feedback. Although you would never want to dump raw error messages to the user in a production environment, just do something such as "a problem occurred, please try again later". But, you can either check for those errors and log them or echo them out in a non-prod environment. I also don't think that running "code" within HTML is a good idea, makes maintainability more difficult. <?php $result = $odb->query("SELECT `Tab` FROM `SiteConfig` LIMIT 1"); if(!$result) { $title = "Unable to retrieve title"; //Add additional error handling to get the real error info } else { $title = $result->fetchColumn(0); } ?> <title><?php echo $title; ?></title> Quote Link to comment https://forums.phpfreaks.com/topic/291126-how-do-i-fix-this/#findComment-1491395 Share on other sites More sharing options...
rizmah Posted September 17, 2014 Author Share Posted September 17, 2014 Most likely your query is failing. The error is telling you that the method fetchColumn() is trying to be executed against a non-object. In that line of code there is "$odb->query()" being used to execute a query and then "->fetchColumn(0)" is attempting to be executed against that result. If the query fails there is nothing for fetchColumn() to execute against. You have no error handling in that code. IMO, you should never assume queries will pass. You should always include error handling to at least provide the user some feedback. Although you would never want to dump raw error messages to the user in a production environment, just do something such as "a problem occurred, please try again later". But, you can either check for those errors and log them or echo them out in a non-prod environment. I also don't think that running "code" within HTML is a good idea, makes maintainability more difficult. <?php $result = $odb->query("SELECT `Tab` FROM `SiteConfig` LIMIT 1"); if(!$result) { $title = "Unable to retrieve title"; //Add additional error handling to get the real error info } else { $title = $result->fetchColumn(0); } ?> <title><?php echo $title; ?></title> I didn't make this code, im editing to fit my needs. I tried your code, still white screen. P.S. I'm a newb. Quote Link to comment https://forums.phpfreaks.com/topic/291126-how-do-i-fix-this/#findComment-1491398 Share on other sites More sharing options...
jazzman1 Posted September 17, 2014 Share Posted September 17, 2014 (edited) You need to connect to mysql server, then you need to create a database, after then you need to create a table with the same name of the query. Don't waste the people time. Edited September 17, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/291126-how-do-i-fix-this/#findComment-1491399 Share on other sites More sharing options...
Solution rizmah Posted September 17, 2014 Author Solution Share Posted September 17, 2014 Done it now, I had an SQL database already setup it was just a stupid problem that took 2 secs to fix. Please close staff. Quote Link to comment https://forums.phpfreaks.com/topic/291126-how-do-i-fix-this/#findComment-1491401 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.