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

using xenforo database connection

Discussion in 'XenForo Development Discussions' started by anmol dubey, Oct 29, 2015.

  1. anmol dubey

    anmol dubey Member

    I have created a table in xenforo database and now i want to insert some values into the table via a php file which is kept at xenforo home directory. I am currently creating connection everytime the php file is called as below

    $con = mysql_connect("localhost","XXXXX","YYYYY");

    if (!$con)
    die('Could not connect: ' . mysql_error());

    $db_selected = mysql_select_db("XXXX",$con);

    if (!$db_selected)
    die ("Can\'t use test_db : " . mysql_error());

    <Rest of the code to insert values in table>

    Is there a better way to connect to the database?

    I am just starting with devlopment hence such a naive question :)
  2. anmol dubey

    anmol dubey Member

  3. Robust

    Robust Well-Known Member

    If wanting to connect to the XF DB, a _getDb function is available to access the XF database in a lot of areas in XF, and if not you can get the db from XenForo_Application too I believe

    If wanting to connect to an external database, use Zend_Db::factory and then use getConnection to establish a connection.
    Last edited: Oct 31, 2015

Share This Page