<?php
///////////////////////////////////////////////////////////////////////////////////////////////////
#  Author:   Anil Kumar
#  Version:	 1.0
#  Date:     25-July-2013
#  Purpose:  WMDSED - DB Handler
#  Requires: Requires PHP5, PDO
#						...
///////////////////////////////////////////////////////////////////////////////////////////////////

require_once("wmdsed-api.php");

///////////////////////////////////////////////////////////////////////////////////////////////////

$db_table_prefix   		= "dompunch_";

///////////////////////////////////////////////////////////////////////////////////////////////////

$db_config_host         = 'localhost'; 		
$db_config_database     = 'dbname_here'; 
$db_config_username     = 'dbuser_here'; 		
$db_config_password     = 'secret_here';

///////////////////////////////////////////////////////////////////////////////////////////////////

$pdo = new wmDomainDatabase($db_table_prefix);
$dbc = $pdo->openMySQL($db_config_host, $db_config_database, $db_config_username, $db_config_password);

///////////////////////////////////////////////////////////////////////////////////////////////////

echo "<pre>";

// Print a list of domains in database

echo "   All .COM Domains in Database that start with 'a'<br><br>";

$darray = $pdo->getDomains('a%.com');
print_r($darray);

// Print a list of .co.uk domains

echo "<br><hr>--- Only .co.uk Domains<br><br>";

$darray = $pdo->getDomains('%.co.uk');
print_r($darray);

// Get all the existing column names

echo "<br><hr>   Get all the existing column names<br><br>";

$darray = $pdo->getAllColumnNames();
print_r($darray);

// Get some data for a specific domain

echo "<br><hr>   Get Data for a specific Domain<br><br>";

$domain = "watch.com";

$columns[] = "registry_expiry";
$columns[] = "registrar_expiry";
$columns[] = "registrar";
$columns[] = "ip";
$columns[] = "ns1";
$columns[] = "ns2";

$darray = $pdo->getDomainData($domain, $columns);
print_r($darray);

// Add a new column the domain table

echo "<br><hr>   Add a new column<br><br>";

$pdo->addTextColumn("invoice_no", 32);

// Set the value for the column for a specific domain

$pdo->setDomainData($domain, "invoice_no", "167238");

// Read back the invoice_no that was set.

unset($columns);
$columns[] = "invoice_no";

$darray = $pdo->getDomainData($domain, $columns);
print_r($darray);

// List all domains that expire before a specific date.

echo "<br><hr>   List domains that expire before Nov 30, 2015<br><br>";

$darray = $pdo->getDomainsFromWhereSQL("registry_expiry < '2015-11-30'");
print_r($darray);

// Show any error log

echo "<br><hr>   Error Log<br><br>";

$pdo->showLog();


///////////////////////////////////////////////////////////////////////////////////////////////////

?>
