Wednesday, July 27, 2016

mysql raw query

        $query = 'SELECT count(*) as total,product_id FROM '.$tablePrefix.'`sales_flat_order_item` WHERE order_id IN (select order_id from '.$tablePrefix.'`sales_flat_order_item` where product_id = '.$productId.') and product_id != '.$productId.' group by product_id order by total desc';
       
        $xml = simplexml_load_file('app/etc/local.xml');
        $host = $xml->global->resources->default_setup->connection->host;
        $username = $xml->global->resources->default_setup->connection->username;
        $password = $xml->global->resources->default_setup->connection->password;
        $dbname = $xml->global->resources->default_setup->connection->dbname;
        $res = mysql_pconnect($host, $username, $password);  
        mysql_select_db($dbname);
        $productIds = mysql_query($query) or die(mysql_error());

        while($fetch = mysql_fetch_array($productIds))
        {}

No comments:

Post a Comment