<html><body>
<?php
if ( $_POST['act'] == "List the titles" ) {
/************************************************************
This program shows how to list the book titles from the
books table.
To use this program, you need to create a table
books by using the following command:
mysql> create table books (
-> title char(128),
-> ISBN char(20) primary key,
-> price real );
Query OK, 0 rows affected (0.07 sec)
*************************************************************/
$host = "undcemmysql.mysql.database.azure.com";
$username = "your_id";
$database = "your_db";
$password = "your-pw";
// 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 );
// Compose the query.
$query = "select title from books where ";
$query = $query . "title like '%" . $_POST['title'] . "%'";
// Execute the query.
$result = $conn->query( $query );
$row = $result->fetch_assoc( );
if ( $result->num_rows > 0 )
// Print the results row by row.
do
echo $row['title'];
while( $row = $result->fetch_assoc( ) );
// Close the database connection.
$conn->close( );
}
elseif ( $_POST["act"] == "Help" ) {
echo "No help at this moment.";
}
else {
echo "No such option: " . $_POST["act"];
}
?>
</body></html>
|