Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2012
    Posts
    4

    Unanswered: Error: Call to a member function query() on a non-object

    Hello,

    I have taken over a project from a colleague who has left the company. He had started to move www.premier-products.co.uk from his own server to our 1and1 hosting account.

    He backed up the database to a .sql file, which I have installed in a new 1and1 database. I can see all the information is there so the database is installed. 1and1 assisted with this. However, when you visit the URL there is the following error:

    Notice: Undefined variable: db in /homepages/23/d409796783/htdocs/premier/index.php on line 41

    Fatal error: Call to a member function query() on a non-object in /homepages/23/d409796783/htdocs/premier/index.php on line 41


    I'm not well-versed in php to fix it. Can you help?

    Tech Specs
    OpenCart 1.5.1
    New server PHP version: 5
    New server MySQL version: 5.0

    If you need me to provide more information, please say.

    Thanks,
    Matthew
    Attached Thumbnails Attached Thumbnails config screenshot.JPG  

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what is the code on line 41 of your script
    /homepages/23/d409796783/htdocs/premier/index.php
    ?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2012
    Posts
    4
    Thanks for your reply.

    Line 41 is:

    $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");

    I have attached the full index.php file in .txt version to this message.
    Attached Files Attached Files

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    try assigning a value to the variable DB before using it as a class
    I expect that you will need to deifne it as a new object
    $db = new <someobject>() as you have already with $registry = new Registry();

    it looks like your code is using the MYSQLi objects
    PHP: mysqli::query - Manual
    the :: is an alternative notation for ->
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jul 2012
    Posts
    4
    Thank you for your assistance healdem. I have solved the issue and the site is in full working order.

Posting Permissions

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