In this example, we will run a SUM…GROUP BY
query in the sales
table to find out how many units are sold for each product, per day. We will store the result in a MongoDB collection. Then we will build a page where the user can enter the date and view the sales data by querying the collection.
1. Create a PHP script name
mysql.php
and put the following code in it:<?php define('MYSQL_HOST', 'localhost'); define('MYSQL_PORT', 3306); define('MYSQL_USER', 'XYZ'); define('MYSQL_PASSWD', '123123'); define('MYSQL_DBNAME', 'acmeproducts'); //function for connecting to MySQL function getMySQLConnection(){ $mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWD, MYSQL_DBNAME, MYSQL_PORT); if (mysqli_connect_error()) { die(sprintf('Error connecting to MySQL. Error No: %d,'. 'Error: %s', mysqli_connect_errno(), mysqli_connect_error())); } return $mysqli; }
2. Open the
dbconnection.php
file and change the value of theDBNAME...