Watch My Domains Server Edition

PHP Interface Library
##########################################################################

The PHP interface library for Watch My Domains SED allows you to
easily access the domain database. You can use it to...

1. Get Domain names that match a specific search criteria.

2. Add extra columns to the domain table.

3. Modify the domain data columns

4. Retrieve the values for any domain data column.

The entire interface is made available as a single file so that you can 
easily add it to your existing PHP projects. 

Here is a typical usage example.

##########################################################################

require_once("wmdsed-api.php");

# These are the settings that are used in the WMD SED config.php file.
# Simply copy it from there.

$db_table_prefix   		= "dompunch_";
$db_config_host         = 'localhost'; 		
$db_config_database     = 'dbname'; 
$db_config_username    	= 'dbuser'; 		
$db_config_password     = 'secret'; 

# Initialize the database

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

# Get a list of all .com domains that start with the letter 'a'.

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

# Add a new text column to the domain table.
# This will create a column called invoice_no and varchar(32)

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

# Now set some value into it for a specific domain
# this assumes that the domain db contains example.com

$pdo->setDomainData("example.com", "invoice_no", "167238");

# Show any errors that were logged.
# Don't call this in production setting

$pdo->showLog();

##########################################################################

Function Reference

##########################################################################

function openMySQL($dbhost, $dbname, $dbuser, $dbpassword)

--------------------------------------------------------------------------

function clearErrors()

Clears any errors.

--------------------------------------------------------------------------

function getLastError()

Gets the last logged error message. 

--------------------------------------------------------------------------

function showLog()

Displays all the logged error messages. Don't use in production setting.

--------------------------------------------------------------------------

function getCategoryIDFromName($category)

Returns the category id from a category name.

--------------------------------------------------------------------------

function getDomainID($domain)

Gets the domain id from a domain name.

--------------------------------------------------------------------------

function getAllColumnNames($tablename="")

Returns an array of all existing domain columns in DB

--------------------------------------------------------------------------

function addTextColumn($name, $charlength, $default='NULL')

Adds a new text column to the domain table (or specify the table name).

--------------------------------------------------------------------------

function addLongTextColumn($name)

Adds a long text column

--------------------------------------------------------------------------

function addDateColumn($name)

Adds a date column

--------------------------------------------------------------------------

function addTimestampColumn($name)

Adds a timestamp column

--------------------------------------------------------------------------

function addBigIntColumn($name, $ilen)

Adds a Integer column

--------------------------------------------------------------------------

function addCustomColumn($columns)

Adds a generic custom column. The $columns should contain 3 entries.

Here is a typical usage example.

$columns[] = "created_at";
$columns[] = "TIMESTAMP";
$columns[] = "DEFAULT '0000-00-00 00:00:00'";

$pdo->addColumns($columns);

--------------------------------------------------------------------------
			
function getDomains($likeString="%")

Returns an array of domains based on the search string.

--------------------------------------------------------------------------

function getDomainsFromWhereSQL($whereSQL)

Usage Example:

$pdo->getDomainsFromWhereSQL("expiry_date < '2014-11-30'");

--------------------------------------------------------------------------

function getDomainsFromSQL($sql)

Usage Example:

$pdo->getDomainsFromWhereSQL("select * from domains where expiry_date < '2014-11-30'");

--------------------------------------------------------------------------

function getDomainData($domain, $columns)

Usage Example:

$columns[] = "registry_expiry";
$columns[] = "registrar_expiry";
$columns[] = "registrar";
$columns[] = "ip";
$columns[] = "ns1";
$columns[] = "ns2";
$ddata = $pdo->getDomainData("example.com", $columns);

--------------------------------------------------------------------------

function setDomainData($domain, $column, $value)

Usage Example:

$pdo->setDomainData($domain, "ip", "192.168.1.1");

--------------------------------------------------------------------------

function setDomainDataArray($domain, $columnArray, $valueArray)

Usage Example:

$column_array = array('moz_pa', 'moz_da', 'moz_links');
$data_array = array(34, 23, 1356);
$pdo->setDomainDataArray($domain, $column_array, $data_array);

--------------------------------------------------------------------------

public getDomainsToLookup($lookuptimefield, $maxdomains, $maxdays)

Find domains that need to be looked up.

$lookuptimefield - The column name that holds the last lookup timestamp.
$maxdomains - maximum number of rows to return
$maxdays - Ignore domains that were looked up $maxdays ago or after.

Returns an array with the following columns 

sid, domain, $lookuptimefield

Usage Example:

$lookup_array = $pdo->getDomainsToLookup("moz_checked_at", $moz_batch_size, $refresh_days);

--------------------------------------------------------------------------


