Anyone knows how to enable INET6_NTOA in mysql 8 ? I just upgraded to 8 version and php 7.4 only to use the in-built function for ipv6… but i get that the function is not defined…
isnt activated out of the box or something ?

It works for me using mysql 8 and php 7.4. Let us see the block of code that’s giving you the error.

it’s not a specific block of codes. everytime i want to use the function(on any block of code) it says that the function inet6_ntoa is not defined but it should be defined and recognized out of the box by mysql and php.
last time i tried was on my bans module to accept ipv6 also not only ipv4.

How about posting the actual text of the error message and an example of how you’re trying to use inet6_ntoa?

the actual error is this
Fatal error : Uncaught Error: Call to undefined function INET6_NTOA() in /var/www/html/admin/bans.php (undefined function which should already be defined in php and mysql from the get go)

and the code using it…

while ($arr = mysqli_fetch_assoc($res)) {
$arr[“first”] = INET6_NTOA($arr[“first”]);
$arr[“last”] = INET6_NTOA($arr[“last”]);

first and last fields are varbinary(16) in the database since varbinary can store ipv6
doing this i was hoping to display the actual ips(v4 and v6) in a human readble text.
if i remove the function from there it works but i can see the varbinary values exactly how they are in the database table

I assume these are ip address. Am I correct? Can you give a sample of the data you’re trying to convert? I’m not familiar with mysqli as I use pdo prepared statements. Are you sure that your

while ($arr = mysqli_fetch_assoc($res))

is actually retrieving data?

The PHP function name is inet_ntop -

yes it does retrive info from the table
.i use inet_pton to insert them
" You don't need a function going the other way because MySQL's INET6_NTOA is already compatible with PHP's inet_pton function." (from the php site)

Thanks for mentioning that. They didn’t say that they were running the code within php rather than html.

after some later edits i can see now the info from the table…in readable form. and using the inet_ntop instead of the mysql’s inet6, i dont know why, but until now the actual fields were blank. they wouldnt print anything

But you weren’t using mysql’s INET6_NTOA() function in a sql query.

yes i am… well i think…because the actual query looks like this for select and insert
SELECT INET6_NTOA(first) AS first, INET6_NTOA(last) AS last FROM bans

I think we have a ‘moving target’ problem between what was posted that produced the php error and what you actually have now.

If you have it working, good.

yes it is working. the ips both v4 and v6 are added properly and also they are displayed properly now

Sponsor our Newsletter | Privacy Policy | Terms of Service