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

using xenforo database connection

#1
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 :)
 

Robust

Well-known member
#3
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: