MyBB Community Forums

Full Version: php or Sql statement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am writing my first MyBB code now.

I am trying to sort categories depending on user hyperlink click.

Might not use name(fid?) depending on index. Not sure correct parameter syntax


<?php
$Selected= $_REQUEST["subject"];
UPDATE mybb_forums SET disporder = '2' WHERE disporder = '1';
UPDATE mybb_forums SET disporder = '1' WHERE name = $Selected;
?>


So what makes more sense try and write this as php script. Or try to just send a SQL statement to the database? I doubt this would run much faster as a stored procedure.
You would be better off with a PHP script, but you definitely need to escape the data before using it against the database.
Ok I'm trying for the Sql code solution.

I got first part to work in php but I need to get both sql statements  to work.
I thought there was a MyBB object $db that magically let me query the MyBB database? Do I need a full connection string to run a string to to get rid of escape the data?
I can't seem to run any kind of query yet.
Are these supposed to be single or double quotes?
I added this to the top after <?php
<?php
define("IN_MYBB",1);
require_once("global.php");
.
.
.

None of these worked. I keep getting server error.
$query =  $db->query("UPDATE 'mybb_forums' SET 'disporder' = '2' WHERE 'disporder' = '1'");
$query =  $db->query("UPDATE mybb_forums SET disporder = 2 WHERE disporder = 1");
$query = $db->query('SELECT * FROM mybb_forums');
$query = $db->query('SELECT * FROM' .mybb_forums);









you can also use here all MyBB objects, functions and stuff
so answering your post title "how to access MyBB database user table from my own php script" you could do

PHP Code:
    $query = $db->query('
            SELECT * FROM '.TABLE_PREFIX.'users
            WHERE uid = '.intval($mybb->user["uid"]).'
        '); 

NM go it to work fine. Will post answer btw.