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

How to launch a query?

Discussion in 'XenForo Development Discussions' started by Lu Jia, May 16, 2011.

  1. Lu Jia

    Lu Jia Active Member

    Hi,
    I wont to create a new table for my forum to record some new data. I want to know witch syntax should I use to launch a query.
    I guess form with post method to other page with a callback with some php code?
     
  2. Lawrence

    Lawrence Well-Known Member

    Do you want this done by a plugin (installer), or just a one time shot for your personal use via phpMyAdmin?

    Moved to Development, :)
     
  3. Lu Jia

    Lu Jia Active Member

    I need to create a "component" and I found External Page good for my work. I just need to know how can I send some data to mysql and how can I select some data from database too.
    - I create a page with the form;
    - I used method post to a second page;
    At the moment i'm using this method:
    PHP:
    $conn = @new mysqli('localhost','databaase','user','password');
    if (
    mysqli_connect_errno() != 0)
    {
    $errno mysql_connect_errno();
    $errmsg mysql_connect_error();
    echo 
    "Connect Failed with ($errno$errmsg<br />\n";
    exit;
    }
    to connect to the database because I haven't found xen API to connect to db
    and I'm using this code:

    PHP:
    $query_create_acl "INSERT INTO $dbname.group_acl (id_group, name, admin) VALUES ('$group_id', '$groupname', '$adminacl')";
    $result_create_acl = @$conn->query($query_create_acl);
    if (
    $result_create_acl === FALSE)
    {
    $errno $conn->errno;
    $errmsg $conn->error;
    echo 
    "Connect Failed with ($errno$errmsg<br />\n";
    $conn->close();
    exit;
    }
    else
    {
    echo 
    "Created new group_acl with id_group: {$conn->insert_id}";
    $group_acl_id $conn->insert_id;
    }
    to add some data. I want to know some easier way to do it and how can I output the data in a xenforo template.
    Thanks in advance
     
  4. Marc

    Marc Well-Known Member

    Best advice I can give (baring in mind I cant give any other at the moment as learning myself) is to watch all of kiers video in this section http://xenforo.com/community/forums/official-development-tutorials-and-resources.41/ and also have a good read through Laurences tutorial on creating addons here http://xenforo.com/community/threads/creating-an-addon.5416/

    Also download a couple of small addons that use database functionality of their own and have a look at how they are doing it. Would suggest something like http://xenforo.com/community/threads/post-content-find-replace.6548/page-6#post-209158 for no other reason than it extends another class you should be able to have a look at if you are using something like eclipse, it connects to the database, and it was coded by kier so you know it was done in the correct manor.

    Im only suggesting this way of learning as this is how I am starting to learn at the moment, however someone else may suggest differently
     
  5. Lu Jia

    Lu Jia Active Member

    Thanks for the tips, I'll do it!
     
  6. Lu Jia

    Lu Jia Active Member

    This one is the solution if someone else need it too:

    PHP:
    $db XenForo_Application::get('db');
    $db->query("INSERT INTO `xf_Mikey` (`threadid`, `userid`, `date`, `blurb`) VALUES ('$threadid', '$userid', '$date' '$blurb');");
     
    bottiger and Marc like this.

Share This Page