Net_MAC::__construct (
object $db
, array $options
)
This is the constructor that will create and populate a valid Net_MAC object.
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:
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 |
void - No return value. A Net_MAC_Exception Exception object will be thrown if there is an error during construction
The constructor can throw exceptions on error, so the constructor should always be called from inside a try/catch block.
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 Net_MAC_Exception