<?php
/**
 * Created by PhpStorm.
 * User: varun
 * Date: 21/11/15
 * Time: 10:38 PM
 */

namespace App\Http\Controllers\Action;

use DB;
use mysqli ;


class News
{
    public function qryToCommaSepString($sqlQry, $uniqueResult = 'Y', &$countOfArr = 0)
    {
        $mysqli = new mysqli( env('DB_HOST_WORDPRESS') , env('DB_USERNAME_WORDPRESS'), env('DB_PASSWORD_WORDPRESS'), env('DB_DATABASE_WORDPRESS'));
//        $sqlQry = "select meta_id from cdb_commentmeta" ;
        $result = $mysqli->query($sqlQry) ;
//        $result = DB::connection('mysql_wordpress')->select($sqlQry) ;
//        print_r($result);
        $namesW=array();
        $dist_emails= "";
        while ( $row = mysqli_fetch_array($result) )
        {
            $namesW[]=array_values($row)[0];
        }
        $countOfArr = count($namesW);
        if( 'Y' == $uniqueResult )
            $dist_emails = implode(',',array_values(array_unique(array_filter($namesW))));
        else
            $dist_emails = implode(',',$namesW);

        $mysqli->close();
        return $dist_emails;
    }
}