MySQL has a BINARY
/VARBINARY
type, which could be used to store binary data directly, without compute it into a hexadecimal representation.
CREATE TABLE `%s` (
`binary_start` BINARY( 20 ) NOT NULL,
`binary_end` VARBINARY( 20 ) NOT NULL,
);
If you use prepared statements and pass the values without concatenating them to a string, the binary data will be inserted "as is".
/** @var $database \PDO */
$stmt = $database->prepare( 'INSERT INTO `ip_table` (`binary_start`, `binary_end`) VALUES ( :start, :end );' );
$stmt->bindValue( ':start', $binaryStart );
$stmt->bindValue( ':end', $binaryEnd );