MyBB Community Forums

Full Version: Run query from different database in mybb
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. I'm trying to make plugin that will run a query from another database (My CMS one) to show recent posts from my CMS. That's what I made:

   if ( !is_array($permissioncache) ||(is_array($permissioncache) && ((count($permissioncache)==1) && (isset($permissioncache['-1']) && ($permissioncache['-1'] = "1"))))) 
       $permissioncache = forum_permissions();

$DB_USER = "X";
$DB_NAME = "X";
$DB_PASS = "X";
$con = mysql_connect("localhost","$DB_USER","$DB_PASS");
$select = mysql_select_db("$DB_NAME");
	$query = mysql_query("
	SELECT *
	FROM articles
	WHERE isActive= 1
	ORDER BY id DESC LIMIT " . $mybb->settings['limit']);
	while($threadRow = $db->fetch_array($query))
	{
	$authorid = mysql_query("SELECT userid FROM users WHERE username='".$threadRow['author']."'");
	$authori = fetch_array($authorid);
		$topdown .= '<tr>';
		$subject = my_substr($threadRow['name'], 0, 50);
		$subject = htmlspecialchars_uni($subject);

		$topdown .= '<td class="trow1">
		<font size="2"><a href="X">' . $subject .'</a> '  . $lang->download_by . (!empty($threadRow['author']) ? ' <a href="X'">' . $threadRow['author'] . '</a>' : $threadRow['author']) . ' (<a href="X>' . $threadRow['category'] . '</a></font>)
		</td>
		<td class="trow1">'.$threadRow['date2'].'
		</td>
		</tr>';
	}


	$topdown .= "</table><br />";

MyBB gives me about 6 different errors from starnge files. why? and how I can do this working?
I do the same in one of my plugins, check out how I did it

http://mods.mybb.com/view/cpmuserlink
(2011-11-12, 07:09 PM)pavemen Wrote: [ -> ]I do the same in one of my plugins, check out how I did it

http://mods.mybb.com/view/cpmuserlink

Too complicated.. can't you just tell me how to connect to different database?
require_once MYBB_ROOT."inc/db_mysql.php";
$db2 = new DB_MySQL;
define("TABLE_PREFIX_2", 'DATABASE TABLE PREFIX');
$db2->connect('DATABASE NAME');
$db2->set_table_prefix(TABLE_PREFIX_2);
$db2->type = 'mysqli';

You should then be able to use all the methods of the MyBB database class using the $db2 reference variable.
(2011-11-13, 03:00 PM)TheUnreal Wrote: [ -> ]
(2011-11-12, 07:09 PM)pavemen Wrote: [ -> ]I do the same in one of my plugins, check out how I did it

http://mods.mybb.com/view/cpmuserlink

Too complicated.. can't you just tell me how to connect to different database?

Too lazy, need me to breathe for you too?
(2011-11-13, 04:10 PM)euantor Wrote: [ -> ]
require_once MYBB_ROOT."inc/db_mysql.php";
$db2 = new DB_MySQL;
define("TABLE_PREFIX_2", 'DATABASE TABLE PREFIX');
$db2->connect('DATABASE NAME');
$db2->set_table_prefix(TABLE_PREFIX_2);
$db2->type = 'mysqli';

You should then be able to use all the methods of the MyBB database class using the $db2 reference variable.

it gives my mybb error : "unable to connect to database"

and to the person above: Your the one who lazy here, I'm asking for help in this forum and except from people to help me and not just send me links to 500 line code and say "search yourself" when your the one who experienced with my issue before, and I'm trying to solve it.
there is a single function in the that code, that works exactly like you need that tells you what you need to know with most, if not all, the issues you may encounter covered.
(2011-11-17, 06:16 PM)TheUnreal Wrote: [ -> ]
(2011-11-13, 04:10 PM)euantor Wrote: [ -> ]
require_once MYBB_ROOT."inc/db_mysql.php";
$db2 = new DB_MySQL;
define("TABLE_PREFIX_2", 'DATABASE TABLE PREFIX');
$db2->connect('DATABASE NAME');
$db2->set_table_prefix(TABLE_PREFIX_2);
$db2->type = 'mysqli';

You should then be able to use all the methods of the MyBB database class using the $db2 reference variable.

it gives my mybb error : "unable to connect to database"

and to the person above: Your the one who lazy here, I'm asking for help in this forum and except from people to help me and not just send me links to 500 line code and say "search yourself" when your the one who experienced with my issue before, and I'm trying to solve it.

You don't have a database user or database password parameter supplied.
Edit:

I give up, you have too many mistakes in your code... Re-learn PHP
(2011-11-17, 06:16 PM)TheUnreal Wrote: [ -> ]and to the person above: Your the one who lazy here, I'm asking for help in this forum and except from people to help me and not just send me links to 500 line code and say "search yourself" when your the one who experienced with my issue before, and I'm trying to solve it.

This is a MyBB Software support forum, and not MyBB plugin support forum!!!
So at least try to be nice..