Net_MAC::__construct()

Net_MAC::__construct() – Constructor

Synopsis

require_once 'Net/MAC.php';

Net_MAC::__construct ( object $db , array $options )

Description

This is the constructor that will create and populate a valid Net_MAC object.

Parameter

  • object $db - This parameter must be a valid MDB2 object.

  • array $options - An array of options to use with the database in retrieving MAC address vendors. The associative array should have key/value pairs as follows:

    Net_MAC::__construct() options
    Option Description
    tablename The name of the table where MAC address vendor information lives
    macaddrcol The name of the column containing the MAC address prefixes
    vendorcol The name of the column containing the vendor name
    desccol The name of the column containing any extra descriptive information derived from the vendor list

Return value

void - No return value. A Net_MAC_Exception Exception object will be thrown if there is an error during construction

Note

The constructor can throw exceptions on error, so the constructor should always be called from inside a try/catch block.

Example

Instantiating a Net_MAC object

<?php
require_once 'Net/MAC.php';
require_once 
'MDB2.php';

$db_type 'pgsql';
$db_host 'localhost';
$db_user 'username';
$db_name 'dbname';
$db_pass 'password';

$dsn "$db_type://$db_user:$db_pass@$db_host/$db_name";

$dbh =& MDB2::factory($dsn);

if (
MDB2::isError($dbh)) {
  echo 
"MDB2 Error: ".$dbh->getUserInfo();
}

$dboptions = array('tablename' => 'macvendors',
           
'macaddrcol' => 'macaddr',
           
'vendorcol' => 'vendor',
           
'desccol' => 'description');

try {
  
$nmh =& new Net_MAC($dbh$dboptions);
} catch (
Net_MAC_Exception $e) {
  echo 
'Net_MAC Error: ' $e->getMessage();
  exit;
}
?>

Throws

throws Net_MAC_Exception

Cleanly formats Media Access Control (MAC) addresses (Previous) Sets the MAC address in the object (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.