开发者

Why PHP Error: Call to a member function set_prefix() on a non-object

I got this error

Fatal error: Call to a member function set_prefix() on a non-object in /home/reboltutorial/reboltutorial.com/wp-settings.php on line 254

line 254 contains:

$prefix = $wpdb->set_prefix($table_prefix); // set up global tables

This occurs if I try to call index_wordpress() instead of calling these two lines

    define('WP_USE_THEMES', true);  
    require('./wp-blog-header.php');  

so this doesn't work:

<?php

    function index_wordpress() {
        define('WP_USE_THEMES', true);  
        require('./wp-blog-header.php');  
    }
?>    

<?php

    if(!function_exists('apache_request_headers')) {
        function apache_request_headers() {
            $headers = array();
            foreach($_SERVER as $key => $value) {
                if(substr($key, 0, 5) == 'HTTP_') {
        开发者_开发知识库            $headers[str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))))] = $value;
                }
            }
            return $headers;
        }
    }

    function getCurrentPageUrl() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     return $pageURL;
    }    

    $a =  apache_request_headers();

    $pos = strrpos($a["User-Agent"], "REBOL");
    if ($pos === false) {
        index_wordpress();
    } else {

      if ($_SERVER['REMOTE_ADDR'] != "69.163.203.14") {
        $command= './cgi-bin/index.cgi '. '"' . getCurrentPageUrl() . '"';
        echo system($command);
      } else {
        index_wordpress(); 
      }
    }
?>

while this works:

<?php

    if(!function_exists('apache_request_headers')) {
        function apache_request_headers() {
            $headers = array();
            foreach($_SERVER as $key => $value) {
                if(substr($key, 0, 5) == 'HTTP_') {
                    $headers[str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))))] = $value;
                }
            }
            return $headers;
        }
    }

    function getCurrentPageUrl() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     return $pageURL;
    }    

    $a =  apache_request_headers();

    $pos = strrpos($a["User-Agent"], "REBOL");
    if ($pos === false) {
        define('WP_USE_THEMES', true);  
        require('./wp-blog-header.php');
    } else {

      if ($_SERVER['REMOTE_ADDR'] != "69.163.203.14") {
        $command= './cgi-bin/index.cgi '. '"' . getCurrentPageUrl() . '"';
        echo system($command);
      } else {
        define('WP_USE_THEMES', true);  
        require('./wp-blog-header.php'); 
      }
    }
?>


You have moved the include that initializes Wordpress into a function, thus limiting all the variables the init procedure creates to the scope of that function, losing them when the function ends.

While this should fix your immediate problem:

 function index_wordpress() {
        global $wpdb;  // Changes scope    
        define('WP_USE_THEMES', true);  
        require('./wp-blog-header.php');  
    }

it is probably better to leave the require in the main script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜