I am trying to one existing procedural mysql query to oop query. Input Data:
$select="visitor_country";
$startDate="2016-01-01";
$endDate="2016-12-31";
$groupBy="visitor_country";
require_once 'libraries/database.connect.php';
procedural mysql query
$conAnalytics=@analyticsdbconnect::getSettings();
$countryQuery=sprintf("SELECT visitor_country,COUNT(*) as count FROM `analytics`.`analytics` WHERE date BETWEEN '2016-01-01' AND '2016-12-31'GROUP BY visitor_country ORDER BY count DESC");
$countrySqlQuery=mysqli_query($conAnalytics, $countryQuery)or die(mysqli_error());
$countryRow=mysqli_fetch_row($countrySqlQuery);
$countryRowCount=count($countryRow);
print_r($countryRow);
Current OOP Query
$query=$connection->prepare("SELECT ?, COUNT(*) as count FROM `analytics`.`analytics` WHERE date BETWEEN ? AND ? GROUP BY ? ORDER BY count");
$query->bind_param('ssss',$select,$startDate,$endDate,$select);
$query->execute();
$result=$query->get_result();
$row=$result->fetch_row();
print_r($row);
$query->close();
$connection->close();
It's a mysql COUNT function to check users visit as per country. The procedural works fine since I have only one entry it dose show one country on
Array ( [0] => India [1] => 1 )
. However the oop one is giving me some trouble. Whenever I am trying to print the value I am getting output
Array ( [0] => visitor_country [1] => 2 )
as visitor_country which is mysql column heading.
I trying to create a class and function so, similar queries could be process by one function and rendered in google chart.