<html><body>
<?php
$username = "user_id";
$database = "user_id";
$password = "p-word";
$host = "undcemmysql.mysql.database.azure.com";
// Initializing MySQLi
$conn = mysqli_init( );
// Creating an SSL connection
mysqli_ssl_set( $conn, NULL, NULL, "DigiCertGlobalRootCA.crt.pem", NULL, NULL );
// Opening a new connection to the MySQL server
mysqli_real_connect( $conn, $host, $username, $password, $database, 3306 );
// Connect to the database.
if ( $conn->connect_errno )
die( 'Failed to connect to MySQL: ' . $conn->connect_error );
$action = Drop Create
Insert ( $titles = "" )
|
if ( $action == "Drop" ) {
// Drop table Reports.
$conn->query( "DROP TABLE Reports" );
echo "Table Reports dropped";
}
|
elseif ( $action == "Create" ) {
// Create table Reports.
$sql = "CREATE TABLE Reports (
reportID INT NOT NULL AUTO_INCREMENT,
title VARCHAR(32) NOT NULL,
PRIMARY KEY( reportID ) )";
$conn->query( $sql );
echo "Table Reports created";
}
|
elseif ( $action == "Insert" ) {
// Insert reports.
$title = strtok( $_POST['titles'], " " );
while ( $title != false ) {
$sql = "INSERT INTO Reports( title ) VALUES( '$title' )";
$conn->query( $sql );
$title = strtok( " " );
}
$sql = "SELECT * FROM Reports";
$result = $conn->query( $sql );
// Print the results row by row.
if ( mysqli_num_rows( $result ) > 0 )
while ( $row = $result->fetch_assoc( ) )
echo $row['reportID'] . " 🠞 " . $row['title'];
else
echo "Error selecting reports: " . $conn->error;
}
// Close the database connection.
$conn->close( );
?>
</body></html>
|
|