O'Reilly logo

PHP and MongoDB Web Development by Rubayeet Islam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - storing the daily sales history of products in MongoDB

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required