Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.

Database Manipulation

I have a few questions about database manipulation in Vanilla forums. I am using version 3.3. How do you update a record in a database in vanilla forums? I tried just using the regular algorithm used, but it does not work.

Comments

  • Phpmyadmin

  • pitkmipitkmi scifi-meshes.com New

    I use MySQL Workbench

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    What is the "regular algorithm"? If you say what you have done right now, it would be easier to give advice. From within a plugin you would either use the model or a model and the methods update or setField.

    DiscussionModel::instance()->setField($discussionID, 'InsertUserID', 9);
    

    or

    $someModel = new Gdn_Model('SomeTable');
    $someModel->update(['Name' => 'New Name', 'Body' = 'New Body'], ['ID' => 3]);
    



  • By "regular algorithm", I mean the MySQL one. Here is a link to the algorithm I used: https://www.w3schools.com/php/php_mysql_update.asp

    I used the mysqli object oriented version. How do you use the examples you gave me? Where do you insert those codes? Is there any other codes that needs to go with them?

    Thanks!

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    As I've said "from within a plugin": https://docs.vanillaforums.com/developer/addons/addon-quickstart/


    If you want to extend Vanillas functionality, the cleanest approach is to write a plugin. If you have set up a basic plugin, you can put the code above e.g. in a method "public function pluginController_dbtest_create()" so that it will be executed when you visit yourforum.com/plugin/dbtest


    Bleistivt
  • Thanks for the help R_I. I will give it a try.

Sign In or Register to comment.