Convert ip 66.249.75.215 to 0x249f94bd7 via $pdo->prepare

How do I update a table and convert say, 66.249.75.215, from one column to another column as 0x249f94bd7. Both columns are varbinary. I’m using PDOConnect and this isn’t working:

$stmt = $pdo->prepare("UPDATE `download` SET `ip_address` = (?) WHERE ip_address is null");
$stmt->execute(inet_aton(`ADDRESS`)) ;

I’m getting the following error:

Fatal error: Uncaught Error: Call to undefined function inet6_aton() in /home/larry/web/test/public_html/index.php:31 Stack trace: #0 {main} thrown in /home/larry/web/test/public_html/index.php on line 31

Thanks in advance

Well, the inet_aton() function creates an “UNSIGNED INTEGER”. Therefore your field can not be a
binary format, but, needs to be INTEGER. Hope that helps.

To store values generated by INET_ATON(), use an INT UNSIGNED column

https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_inet-aton

Sponsor our Newsletter | Privacy Policy | Terms of Service