How to launch a query?

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?
 
Do you want this done by a plugin (installer), or just a one time shot for your personal use via phpMyAdmin?

Moved to Development, :)
 
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
 
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
 
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');");
 
Top Bottom