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

Php Connect to DB

Discussion in 'General PHP and MySQL Discussions' started by KCGaming, Apr 15, 2014.

  1. KCGaming

    KCGaming Member

    I'm trying to create a script to look at user on my team speak and game servers and assign points through the credits addon for use of clans servers. (this scraping of the servers I have done already)

    I want to create a direct connection to the database from the script what commands does Xenforo use to connect to the database

    I was going to use
    mysql_connect("""UserName""Password ") or die(mysql_error());
    mysql_select_db("Database") or die(mysql_error());
    But the functions I see in credits code uses

    $db $this->_getDb();
    How would I align my database connect so I can talk to the database this way

    Thanks in advance for any help (I have 10 days off work and would like to get this done)
  2. KCGaming

    KCGaming Member

    Here is the code I'm using to get some user id info and connect to the database


    ('XF_ROOT'$_SERVER['DOCUMENT_ROOT'] . ''); // set this!
    define('SESSION_BYPASS'false); // if true: logged in user info and sessions are not needed
    require_once(XF_ROOT '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader(XF_ROOT '/library');
    XenForo_Application::initialize(XF_ROOT '/library'XF_ROOT);
    error_reporting(E_ALL & ~E_NOTICE); // Turn off the strict error reporting.
    $dependencies = new XenForo_Dependencies_Public();

    //Get the default options from XenForo.
    $options XenForo_Application::get('options');

    $userid="4"// set this to what ever as an example im setting it as 4
    $userinfo XenForo_Model::create('XenForo_Model_User')->
    getUserById($userid,array('join' => XenForo_Model_User::FETCH_USER_FULL ));                              


    $db XenForo_Application::getDb(); // this load the database up will write and read date here soon
    I will be writing data soon to the database

Share This Page