Jump to content

How do I fix this?


Go to solution Solved by rizmah,

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/291126-how-do-i-fix-this/
Share on other sites

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>
Link to comment
https://forums.phpfreaks.com/topic/291126-how-do-i-fix-this/#findComment-1491395
Share on other sites

 

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.

Link to comment
https://forums.phpfreaks.com/topic/291126-how-do-i-fix-this/#findComment-1491398
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.