SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2010
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Class name must be a valid object or a string

    I am receiving the above error message in one of my PHP Scripts and wondered if somebody could give me a clue as to what it means...

    The file path it gives me at the end of the error message leads me to a piece of code that, as far as I can tell, contains no class names. That code is here:



    Code PHP:
    // -------------------------------------------------------------------------------------------------
    // INCLUDES AND SETUP
    // -------------------------------------------------------------------------------------------------
    $phpEx = 'php';
    $phpbb_root_path = get_option( 'wp2bb_phpbbpath' ) . '/';
    $host = get_option( 'wp2bb_wpurl' );
    $username=get_option( 'wp2bb_username' );
    $usercolour=get_option( 'wp2bb_usercolor' );
     
    include("wp2bbforum.php");
    include("wp2bbadmin.php");
     
    if (file_exists($phpbb_root_path . '/config.php')) {
      $db = new $sql_db();
      $cache = new cache();
    }

    The line number the error message refers to, within the above piece of code, corresponds to the line that says:

    Code PHP:
    $db = new $sql_db();

    Can anyone point me in the right direction to troubleshoot this script?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The variable $sql_db should likely have been set in one of those include files.

    It would probably be something like "Mysql" so that call would become:
    PHP Code:
    $db = new Mysql(); 
    vs something like SQLServer() or PostGres()

    You had better check those include files - which in turn could have include files of their own.

    Most likely candidate looks like config.php

  3. #3
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    The variable $sql_db should be set by phpBB, but for some reason it doesn't look like it is. Are you are all of the files are in the correct place? Try seeing where $phpbb_root_path . 'includes/db/dbal.php' is (echo() it) and see if that file exists?

    You could hard-code the class name (probably dbal_mysql) but it's probably best to get the variable loaded properly.
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •