<?php
# SQL> CREATE TABLE keywords (
# 2 kwID INT AUTO_INCREMENT PRIMARY KEY,
# 3 keyword VARCHAR(64) );
#
# SQL> CREATE TABLE url_title (
# 2 urlID INT AUTO_INCREMENT PRIMARY KEY,
# 3 url VARCHAR(128),
# 4 title VARCHAR(128) );
#
# SQL> CREATE TABLE www_index (
# 2 kwID INT,
# 3 urlID INT,
# 4 PRIMARY KEY ( kwID, urlID ),
# 5 FOREIGN KEY ( kwID ) REFERENCES keywords ( kwID ),
# 6 FOREIGN KEY ( urlID ) REFERENCES url_title ( urlID ) );
include 'password.php'; // Containing only one line: $password="your-pw";
$keyword = $argv[1];
$host = "undcemmysql.mysql.database.azure.com";
$username = "your-id";
$database = "your-db";
$conn = mysqli_init( );
mysqli_ssl_set( $conn, NULL, NULL, "DigiCertGlobalRootCA.crt.pem", NULL, NULL );
mysqli_real_connect( $conn, $host, $username, $password, $database, 3306 );
if ( mysqli_connect_errno( ) )
die( 'Failed to connect to MySQL: ' . mysqli_connect_error( ) );
# SELECT k.keyword, u.url, u.title FROM keywords k, url_title u, www_index w
# WHERE k.keyword LIKE '%$keyword%' AND k.kwID=w.kwID AND w.urlID=u.urlID;
$no = 1;
$query = "SELECT k.keyword, u.url, u.title FROM keywords k, url_title u, www_index w WHERE ";
$query .= "k.keyword LIKE '%" . $keyword . "%' AND k.kwID=w.kwID AND w.urlID=u.urlID;";
echo( $query );
echo( "<table width='98%' border='1' bgcolor='lightyellow'>" );
echo( "<tr><th width='05%'>No.</th>" );
echo( "<th width='15%'>Keyword</th>" );
echo( "<th width='30%'>URL</th>" );
echo( "<th width='50%'>Title</th></tr>" );
$result = mysqli_query( $conn, $query );
$row = mysqli_fetch_assoc( $result );
if ( mysqli_num_rows( $result ) > 0 )
// Print the results row by row.
do {
echo( "<tr><td>". $no++ . "</td><td>" . $row['keyword'] );
echo( "</td><td><a target='_blank' href='" . $row['url'] . "'>" . $row['url'] );
echo( "</a></td><td>" . $row['title'] . "</td></tr>" );
} while( $row = mysqli_fetch_assoc( $result ) );
echo( "</table>" );
// Close the connection.
mysqli_close( $conn );
?>
|