<?php
// ExeOutput for PHP: MySQL sample using the WAMP package Server2Go

// By default, Server2go comes with a sample database. Root admin is not password-protected.
$mysqlusername = "root";
$mysqlpass = "";
// Do not modify the following lines
$mysqlport = getenv('S2G_MYSQL_PORT');
$mysqlhost = "localhost:".$mysqlport;

// We verify that our ExeOutput application was started by Server2go, otherwise, the MySQL server may not have started.
if (empty($mysqlport)) die("This application cannot be started directly. Programmers: please use the Server2go EXE file, it will start this application automatically.");

?>     
<html>
<head>
<title>MySQL Demo with ExeOutput and Server2Go</title>
</head>
<body>
  <p>If you want to edit the local database, Server2Go comes with phpMyAdmin: click the following link to open it and make your changes: <a href="<?php $apacheport = getenv('S2G_APACHE_PORT'); echo("http://localhost:$apacheport/phpmyadmin"); ?>">phpMyAdmin</a></p>
  
  <div id="container">
  	<div id="main">

    This sample PHP script shows how to use a MySQL database with Server2Go in an application compiled with ExeOutput for PHP. 
        <br><br>
        <table style="font-size: 9pt;">
        	<tr>
        		<td style="background-color:#C9C8C8">Name</td>
                <td style="background-color:#C9C8C8">Quantity</td>
        		<td style="background-color:#C9C8C8">Price</td>
        	</tr>
			 <?php 
                $nConnection = mysql_connect($mysqlhost, $mysqlusername, $mysqlpass);
	
            	if ($nConnection)
            	{
            		//--- get maximum count of users
            		if (mysql_select_db("Server2Go", $nConnection))
            		{
            			$query = "select * from items";
            			$nResult = mysql_query($query, $nConnection);
            
            			if ($nResult)
            			{
            				if (mysql_num_rows($nResult) > 0)
            				{
            				    $nIndex = 0;
            					while (	$arrRow = mysql_fetch_array($nResult))
            					{
					    		 	$strColor = ($nIndex % 2 == 0) ? "#E1E1E1" : "#F4f3f3";
                 	
                                    echo "<tr style=\"background-color: $strColor;\">";
                                    echo "<td>".$arrRow["name"]."</td>";
                                    echo "<td>".$arrRow["quantity"]."</td>";
                                    echo "<td>".$arrRow["price"]."</td>";
                                    echo '</tr>'; 
                                    
                                    $nIndex++;
                                }
                            }
                        }
                    }
                }
             ?> 
   				
   	 </div>
   </div>
   
</body>
</html>