MySQL Forums
Forum List  »  Newbie

Re: Unable to upload macadress to mysql
Posted by: robert abshire
Date: August 07, 2014 05:52AM

In database, we can use unsigned BIGINT data type as it can store up to 8 bytes. While reading from database,

SELECT HEX(mac_addr) FROM `devices`;
While saving,

INSERT INTO `devices` (mac_addr) VALUES (x'0123456789AB');
If you prefer to make conversions in PHP,

function mac2int($mac) {
return base_convert($mac, 16, 10);
}

function int2mac($int) {
return base_convert($int, 10, 16);
}
You can use this function to make the address human readable

function int2macaddress($int) {
$hex = base_convert($int, 10, 16);
while (strlen($hex) < 12)
$hex = '0'.$hex;
return strtoupper(implode(':', str_split($hex,2)));
}
BI

CEWS

Options: ReplyQuote


Subject
Written By
Posted
Re: Unable to upload macadress to mysql
August 07, 2014 05:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.