Manuel Pear

Net_MAC::__construct()

Net_MAC::__construct() -- Constructor

Synopsis

  1. <?php
  2. require_once 'Net/MAC.php
  3. ?> 

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

Description

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

Paramètres

  • 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:

    Tableau 54-1. 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

Valeur retournée

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.

Exemple

Exemple 54-1. Instantiating a Net_MAC object

  1. <?php
  2. require_once 'Net/MAC.php';  
  3. require_once 'MDB2.php';  
  4.  
  5. $db_type = 'pgsql';  
  6. $db_host = 'localhost';  
  7. $db_user = 'username';  
  8. $db_name = 'dbname';  
  9. $db_pass = 'password';  
  10.  
  11. $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name";  
  12.  
  13. $dbh =& MDB2::factory($dsn);  
  14.  
  15. if (MDB2::isError($dbh)) {  
  16. echo "MDB2 Error: ".$dbh->getUserInfo();  
  17. }  
  18.  
  19. $dboptions = array('tablename' => 'macvendors', 
  20.             'macaddrcol' => 'macaddr', 
  21.             'vendorcol' => 'vendor', 
  22.             'desccol' => 'description');  
  23.  
  24. try {  
  25. $nmh =& new Net_MAC($dbh, $dboptions);  
  26. } catch (Net_MAC_Exception $e) {  
  27. echo 'Net_MAC Error: ' . $e->getMessage();  
  28. exit;  
  29. ?> 

Valeurs renvoyées

throws Net_MAC_Exception


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique