<?php
echo "<html>
<body>
<table width='100%' height='80%'>
<tr>
<td align='center' valign='middle'>
<h3>";
$host = "undcemmysql.mysql.database.azure.com";
$username = "your-id";
$password = "your-pw";
$database = "your-db";
// Initialize MySQLi.
$conn = mysqli_init( );
// Create an SSL connection.
mysqli_ssl_set( $conn, NULL, NULL, "DigiCertGlobalRootCA.crt.pem", NULL, NULL );
// Open a new connection to the MySQL server.
mysqli_real_connect( $conn, $host, $username, $password, $database, 3306 );
// If fail to connect to the database
if ( mysqli_connect_errno( ) )
die( 'Failed to connect to MySQL: ' . mysqli_connect_error( ) );
if ( $argv[1] == "Drop" ) {
$query = "DROP TABLE Reports";
echo "<font color='#3366CC'><code>$query;</code></font>";
if ( mysqli_query( $conn, $query ) )
echo "Table <em>Reports</em> dropped";
else
echo "Error dropping table <em>Reports</em>: " . mysqli_connect_error( );
}
elseif ( $argv[1] == "Create" ) {
// Create table Reports.
$query = "CREATE TABLE Reports (
reportID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY ( reportID ),
title VARCHAR(32) )";
echo "<font color='#3366CC'><code>$query;</code></font>";
if ( mysqli_query( $conn, $query ) )
echo "Table <em>Reports</em> created";
else
echo "Error creating table <em>Reports</em>: " . mysqli_connect_error( );
}
elseif ( $argv[1] == "Insert" ) {
$title = strtok( $argv[2], " " );
while ( $title != false ) {
$query = "INSERT INTO Reports ( title ) VALUES ( '$title' )";
echo "<font color='#3366CC'><code>$query;</code></font>";
if ( !mysqli_query( $conn, $query ) ) {
echo "Error inserting report: " . mysqli_connect_error( );
die( "unable to insert a report" );
}
$title = strtok( " " );
}
}
elseif ( $argv[1] == "Select" ) {
$query = "SELECT * FROM Reports";
echo "<font color='#3366CC'><code>$query;</code></font>";
$result = mysqli_query( $conn, $query );
$row = mysqli_fetch_assoc( $result );
if ( mysqli_num_rows( $result ) > 0 )
do
echo $row['reportID'] . ", " . $row['title'];
while( $row = mysqli_fetch_assoc( $result ) );
}
elseif ( $argv[1] == "Delete" ) {
$query = "DELETE FROM Reports";
echo "<font color='#3366CC'><code>$query;</code></font>";
if ( mysqli_query( $conn, $query ) )
echo "Table Reports deleted";
else
echo "Error deleting table Reports: " . mysqli_connect_error( );
}
mysqli_close( $conn );
echo " </h3>
</td>
</tr>
</table>
</body>
</html>";
?> |