1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Update a database table on addon install

Discussion in 'XenForo Development Discussions' started by Nudaii, Feb 19, 2014.

  1. Nudaii

    Nudaii Well-Known Member

    I am pretty new to writing php, and i know i have something wrong in this code, but can't work out exactly what it is.
    PHP:
    <?php

    class RrwsTitlePlus_Install
    {
        protected static 
    $table = array(
            
    'installrrwstrop' => 'UPDATE xf_user SET custom_title => TestTitle'

        
    );
        public static function 
    install()
        {
            
    $db XenForo_Application::get('db');
            
    $db->query(self::$table['installrrwstrop']);
        }


    }
    any ideas?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Shouldn't it be
    PHP:
    $db XenForo_Application::getDb();
     
    Nudaii likes this.
  3. Syndol

    Syndol Guest

    Shouldn't => be =
     
    Nudaii likes this.
  4. Nudaii

    Nudaii Well-Known Member

    PHP:
    <?php
    class RrwsTitlePlus_Install
    {
      protected static 
    $table = array(
      
    'installrrwstrop' => 'UPDATE xf_user SET custom_title = TestTitle'
      
    );
      public static function 
    install()
      {
      
    $db XenForo_Application::getDb();
      
    $db->query(self::$table['installrrwstrop']);
      }
    }
    gives this error

    Mysqli prepare error: Unknown column 'TestTitle' in 'field list'

    Basically i need to set default content to all custom usertitles upon addon install.

    i appreciate you guys help.
     
  5. Syndol

    Syndol Guest

    Try
    "UPDATE `xf_user` SET `custom_title` = 'TestTitle'"
     
    Nudaii likes this.
  6. Nudaii

    Nudaii Well-Known Member

    works! thanks guys!
     
    Syndol likes this.
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

    Just a note, that both methods work to get the Database object. :)
     
    Daniel Hood and Nudaii like this.
  8. Aayush

    Aayush Well-Known Member

    It's the same thing, I call get('options') and getOptions both in my code :p
     
    Nudaii likes this.

Share This Page