MyBB Community Forums

Full Version: Adding posts directly to SQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,

I am attempting to add posts directly to the SQL, however they don't seem to "post". Is there a query or something I need to run for them to post?
Why you trying to do it directly from SQL? If this is for an external script, you may as well use the post handler.
Post handler? I've got 200 posts that I need to upload.

Basically, I was thinking that I could just replicate the format of the columns using rows in SQL database, but when I do it doesn't post- of course I am leaving out the hash but I don't think it should matter?

Heres the situation in more detail

1) I have 200 posts (NOT on the forum, in a separate file)
2) I have 200 titles (NOT on the forum, in a separate file)
3) I have created 200 user accounts to assign the posts to.
Have you tried running the recount/rebuild feature in the Admin CP? They won't show up till you run that no matter what you do.

And yeah, the post handler could do it no problem. Set up a PHP script with a loop to 200 and insert each post within the loop.
Yes, if you use the posthandler to insert posts, you give it an array of information and it'll add the post.
Link to "post handler" information? I'm sort of a noob at code, but I think I could figure it out...

Thanks so much for the assistance thus far!
./inc/datahandlers/post.php
Look in ./new/reply.php; the post handler starts at line 379, and it ends up being inserted at line 483, after it's built the array of data and validated it. Basic example:

require_once MYBB_ROOT."inc/datahandlers/post.php";
$posthandler = new PostDataHandler("insert");

$post = array(
	"tid" => $mybb->input['tid'],
	"replyto" => $mybb->input['replyto'],
	"fid" => $thread['fid'],
	"subject" => $mybb->input['subject'],
	"icon" => $mybb->input['icon'],
	"uid" => $uid,
	"username" => $username,
	"message" => $mybb->input['message'],
	"ipaddress" => get_ip(),
	"posthash" => $mybb->input['posthash']
);
$posthandler->set_data($post);
$post_errors = array();
if(!$valid_post)
{
	$post_errors = $posthandler->get_friendly_errors();
}
if(count($post_errors) > 0)
{
	$reply_errors = inline_error($post_errors);
}
else
{
	$postinfo = $posthandler->insert_post();
}
Thanks! Is this correct?

1) I create a TABLE with the posts and information required in the array
2) I make a new php file with this same array information
3) It gets inserted after I "run it"? How do I run it? How do I link it with the TABLE

Thanks so much! Sorry for being such a newb.
It'll insert it into the standard MyBB posts table, not a custom table, why exactly do you need it in a separate table if it'll have the exact same structure as the standard posts table...??
Pages: 1 2