Regarding Creating Database connection and creating new page in Xenforo

gginni

Active member
#1
I created new page in Xenforo giving PHP callback class name and method name.

I want to use different database for that particular xenforo page on my website. Below is content of my file:-

Code:
<?php
class Home_Listener_LoadClassController
{
    public static function respond(XenForo_ControllerPublic_Abstract $controller,  XenForo_ControllerResponse_Abstract $response)
    {
        $page = $controller->getInput()->filterSingle('page', XenForo_Input::UINT);
        $category = $controller->getInput()->filterSingle('category', XenForo_Input::UINT);
        $visitor = XenForo_Visitor::getInstance()->toArray();
        $sessionModel = $controller->getModelFromCache('XenForo_Model_Session');
        $response->params['onlineUsers'] = $sessionModel->getSessionActivityQuickList(
            $visitor,
            array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
            ($visitor['user_id'] ? $visitor : null)
        );

        $mysql_host = "localhost";
        $mysql_database = "xxx";
        $mysql_user = "xxx";
        $mysql_password = "xxx";

        $mysqllink = mysql_connect($mysql_host, $mysql_user, $mysql_password);

        @mysql_select_db($mysql_database) or die("Error");
       
        $query = "SELECT title,price from xxxtable";
        $result = mysql_query($query);
        while($i < $num)
        {
            $title = mysql_result($result, $i, "title");   
            $price = mysql_result($result, $i, "price");
            $html = "Construct HTML using $title and $price";
            $i++
        }
       
        mysql_close($mysqllink);
        $response->params['html'] = $html;
        $response->templateName = 'mytemplate';
    }
}

?>
I'm new in PHP and I don't have much information about creating persistent database connection or whatever we call it.

I saw the google and used the above way for creating database connection and then used it to create HTML. My page is perfectly fine but now problem is performance.

I see lot of performance issue because of this page. Is there any issues in creating database connection the way I did??

What is the best way to create database connection?? Is there any way to create database connection which is always open
 

gginni

Active member
#2
I see performance issue when my concurrent users are around 150-200... My website goes down because of few sql queries running in back-end (I just mentioned one query here in this example but actually I'm using 7-8)... What is the issue in this code??
 
Top